Databases 2 min read

Using ChatGPT to Generate a Shell Script for MySQL Performance Monitoring

This article shares a concise 10‑line Bash script, generated by ChatGPT, that captures MySQL QPS, TPS, and connection counts, timestamps each record, and appends the metrics to a log file for easy performance monitoring.

Advanced AI Application Practice
Advanced AI Application Practice
Advanced AI Application Practice
Using ChatGPT to Generate a Shell Script for MySQL Performance Monitoring

Inspired by a Zhihu question, the author asked ChatGPT to produce a short shell script for monitoring MySQL database performance. ChatGPT returned a 10‑line Bash script that gathers key metrics and writes them to a log.

The script works as follows:

#!/bin/bash
# Get current timestamp
TIMESTAMP=`date +%s`
# Get MySQL QPS, TPS, and connection count
QPS=`mysqladmin -uroot -ppassword status | awk '{print $5}'`
TPS=`mysqladmin -uroot -ppassword status | awk '{print $8}'`
CONNECTIONS=`mysqladmin -uroot -ppassword status | awk '{print $4}'`
# Append results to log file
echo "$TIMESTAMP,$QPS,$TPS,$CONNECTIONS" >> /var/log/mysql_perf.log

The script uses mysqladmin to query the server status, extracts the fifth, eighth, and fourth fields for QPS, TPS, and connections respectively, and records them together with a Unix timestamp. The output is appended to /var/log/mysql_perf.log, creating a simple time‑series log of performance data.

The author notes that such a script is convenient for technical users and suggests trying it out.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ChatGPTMySQLBash
Advanced AI Application Practice
Written by

Advanced AI Application Practice

Advanced AI Application Practice

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.