1.最大连接数监控
show VARIABLES like "max_connections"; //最大连接数 show global status like 'Threads_connected'; //当前连接数 show global status like 'Threads_running'; //正在处理的连接数 show global status like 'Thread%'; //查看进行情况
2.死锁或者阻塞监控
innodb引擎查看死锁语句 select b.trx_mysql_thread_id AS '被阻塞线程', b.trx_query AS '被阻塞SQL', c.trx_mysql_thread_id AS '阻塞线程', (UNIX_TIMESTAMP()-UNIX_TIMESTAMP(c.trx_started)) AS '阻塞时间' from information_schema.INNODB_LOCK_WAITS a join information_schema.INNODB_TRX b on a.requesting_trx_id =b.trx_id join information_schema.INNODB_TRX c on a.blocking_trx_id=c.trx_id where (UNIX_TIMESTAMP()-UNIX_TIMESTAMP(c.trx_started))>60;
3.慢查询配置
-- 打开sql执行记录功能 set global log_output='TABLE'; -- 输出到表 set global log=ON; -- 打开所有命令执行记录功能general_log, 所有语句: 成功和未成功的. set global log_slow_queries=ON; -- 打开慢查询sql记录slow_log, 执行成功的: 慢查询语句和未使用索引的语句 set global long_query_time=0.1; -- 慢查询时间限制(秒) set global log_queries_not_using_indexes=ON; -- 记录未使用索引的sql语句 -- 查询sql执行记录 select * from mysql.slow_log order by 1; -- 执行成功的:慢查询语句,和未使用索引的语句 select * from mysql.general_log order by 1; -- 所有语句: 成功和未成功的. -- 关闭sql执行记录 set global log=OFF; set global log_slow_queries=OFF;