vi /etc/my.cnf
在 [mysqld] 下加入
slow_query_log = 1 #开启慢查询日志 slow_query_log_file = /var/log/mysql-slow.log #指定日志存放地址,mysql5.5及之前版本 log-slow-queries long_query_time = 1 #设置多久视为慢查询 chown mysql:mysql -R /var/log/musql-slow.log
重启mysql
查看设置的变量
mysql> show variables like '%slow%'; +---------------------------+-------------------------+ | Variable_name | Value | +---------------------------+-------------------------+ | log_slow_admin_statements | OFF | | log_slow_slave_statements | OFF | | slow_launch_time | 2 | | slow_query_log | ON | | slow_query_log_file | /var/log/mysql-slow.log | +---------------------------+-------------------------+ 5 rows in set (0.00 sec) mysql> show variables like 'long_query_time'; +-----------------+----------+ | Variable_name | Value | +-----------------+----------+ | long_query_time | 1.000000 | +-----------------+----------+ 1 row in set (0.00 sec)
模拟查询
SELECT SLEEP(5);
查看mysql-slow.log文件
/usr/local/mysql/bin/mysqld, Version: 5.6.40-log (Source distribution). started with: Tcp port: 3306 Unix socket: /tmp/mysql.sock Time Id Command Argument # Time: 181127 19:07:05 # User@Host: root[root] @ localhost [] Id: 1 # Query_time: 5.000253 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0 SET timestamp=1543316825; select sleep(5);
查询mysql连接数
mysql> SHOW status like 'Threads%'; +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | Threads_cached | 1 | | Threads_connected | 1 | | Threads_created | 2 | | Threads_running | 1 | +-------------------+-------+ 4 rows in set (0.00 sec)
查询mysql配置最大连接数
mysql> show variables like 'max_connections'; +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | max_connections | 500 | +-----------------+-------+ 1 row in set (0.00 sec)
本文为Adamin90原创文章,转载无需和我联系,但请注明来自http://www.lixiaopeng.top