1.MySQL线程管理常用命令 1 2 3 4 5 6 7 8 show processlist; show full processlist; show variables; show variables like "%" ; kill ID; show status; show global status; show engine innodb status;
2.MySQL线程超时时间 背景:show processlist;
的时候有过多的 sleep
线程,把总的连接数占满了。
解决方法:设置线程超时时间
查看线程的超时时间 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 mysql> show variables like "%timeout" ; +------------------------------+----------+ | Variable_name | Value | +------------------------------+----------+ | connect_timeout | 10 | | delayed_insert_timeout | 300 | | innodb_flush_log_at_timeout | 1 | | innodb_lock_wait_timeout | 60 | | innodb_rollback_on_timeout | OFF | | interactive_timeout | 28800 | | lock_wait_timeout | 31536000 | | net_read_timeout | 30 | | net_write_timeout | 60 | | rpl_semi_sync_master_timeout | 10000 | | rpl_stop_slave_timeout | 31536000 | | slave_net_timeout | 3600 | | wait_timeout | 28800 | +------------------------------+----------+ 13 rows in set (0.01 sec)
设置线程的超时时间 wait_timeout
要与 interactive_timeout
一起修改才能起效。
1 2 3 4 5 6 7 8 [mysqld] interactive_timeout = 600 wait_timeout = 600 mysql> set global wait_timeout = 600; mysql> set global interactive_timeout = 600;
3.查看mysql全局运行状态 查看状态 1 2 3 show status; show global status; show status like '%select%' ;
4.查看thread 1 2 3 4 5 6 7 8 9 10 11 12 13 14 mysql> show global status like "%thread%" ; +------------------------------------------+-------+ | Variable_name | Value | +------------------------------------------+-------+ | Delayed_insert_threads | 0 | | Performance_schema_thread_classes_lost | 0 | | Performance_schema_thread_instances_lost | 0 | | Slow_launch_threads | 0 | | Threads_cached | 0 | | Threads_connected | 2 | | Threads_created | 2 | | Threads_running | 1 | +------------------------------------------+-------+ 8 rows in set (0.00 sec)