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;