0
点赞
收藏
分享

微信扫一扫

MySQL部分性能查询

使用socket方式连接查询。

一、MySQL单实例部分性能查询

cpu使用率:ps auxw --sort=%cpu |awk 'BEGIN{sum=0}/mysql/ && $0!~/grep/{sum+=$3}END{print sum}'

内存使用率:ps auxw --sort=%cpu |awk 'BEGIN{sum=0}/mysql/ && $0!~/grep/{sum+=$4}END{print sum}'

版本:mysql -V

存活状态:

mysqladmin --defaults-file=/etc/.my.cnf  -Pxxxx -S /tmp/mysql.sock ping | grep -c "alive"

连接数:

mysqladmin --defaults-file=/etc/.my.cnf  -Pxxxx -S /tmp/mysql.sock status| awk {'print $4'}

启动时长:

mysqladmin --defaults-file=/etc/.my.cnf  -Pxxxx -S /tmp/mysql.sock status | cut -f2 -d " "

慢查询次数:

mysqladmin --defaults-file=/etc/.my.cnf  -Pxxxx -S /tmp/mysql.sock status  | cut -f5 -d ':' | cut -d' ' -f2

执行UPDATA操作的次数:

mysqladmin --defaults-file=/etc/.my.cnf  -Pxxxx -S /tmp/mysql.sock extended-status | grep -w "Com_update" | cut -d"|" -f3

执行insert操作的次数:

mysqladmin --defaults-file=/etc/.my.cnf  -Pxxxx -S /tmp/mysql.sock extended-status | grep -w "Com_insert"| cut -d"|" -f3

执行delete操作次数:

mysqladmin --defaults-file=/etc/.my.cnf  -Pxxxx -S /tmp/mysql.sock extended-status | grep -w "Com_delete"|cut -d"|" -f3

执行commit次数:

mysqladmin --defaults-file=/etc/.my.cnf  -Pxxxx -S /tmp/mysql.sock extended-status | grep -w "Com_commit"|cut -d"|" -f3

执行select操作的次数:

mysqladmin --defaults-file=/etc/.my.cnf  -Pxxxx -S /tmp/mysql.sock extended-status | grep -w "Com_insert"|cut -d"|" -f3

执行回滚事务次数(rollback):

mysqladmin --defaults-file=/etc/.my.cnf  -Pxxxx -S /tmp/mysql.sock extended-status | grep -w "Com_rollback"|cut -d"|" -f3

查询次数(Questions):

mysqladmin --defaults-file=/etc/.my.cnf  -Pxxxx -S /tmp/mysql.sock status | cut -d ':' -f4 | cut -d ' ' -f2

MySQL Server从客户端接收的字节数:

mysqladmin --defaults-file=/etc/.my.cnf  -Pxxxx -S /tmp/mysql.sock extended-status | grep -w "Bytes_received" |cut -d"|" -f3

MySQL Server发送给客户端的字节数:

mysqladmin --defaults-file=/etc/.my.cnf  -Pxxxx -S /tmp/mysql.sock extended-status | grep -w "Bytes_sent" |cut -d"|" -f3

开启事务的次数:

mysqladmin --defaults-file=/etc/.my.cnf  -Pxxxx -S /tmp/mysql.sock extended-status | grep -w "Com_begin"|cut -d"|" -f3

innodb平均每秒从文件中写入的次数:

mysqladmin --defaults-file=/etc/.my.cnf  -Pxxxx -S /tmp/mysql.sock extended-status | grep -w "Innodb_data_written"|cut -d"|" -f3

从库的延迟量:

mysql --defaults-file=/etc/.my.cnf  -Pxxxx -S /tmp/mysql.sock -e 'show slave status\G' | grep -E "Seconds_Behind_Master" | cut -d":" -f2


举报

相关推荐

0 条评论