mysql慢查询操作实例分析【开启、测试、确认等】
16lz
2021-12-20
本文实例讲述了mysql慢查询操作。分享给大家供大家参考,具体如下:
mysql有些sql会执行很慢,有可能造成服务器负载飙升
首先查询 确定影响负载的是mysql ,使用top命令,ps命令等
其次,进入MySQL,使用show full processlist查询执行中的sql语句,看看问题,使用explain 命令 查看状态
最后找出sql语句杀死或者优化
centos7上面安装mariadb服务
yum -y install mariadb-server mariadb-devel
more /etc/my.cnf.d/server.cnf
systemctl start mariadb
MariaDB [(none)]> show variables like '%slow_query%';+---------------------+--------------------------------+| Variable_name | Value |+---------------------+--------------------------------+| slow_query_log | ON || slow_query_log_file | /usr/local/mysql/data/slow.log |+---------------------+--------------------------------+2 rows in set (0.00 sec)MariaDB [(none)]> show variables like 'long_query_time';+-----------------+----------+| Variable_name | Value |+-----------------+----------+| long_query_time | 1.000000 |+-----------------+----------+1 row in set (0.00 sec)
MariaDB [(none)]> select sleep(2);+----------+| sleep(2) |+----------+| 0 |+----------+1 row in set (2.00 sec)
MariaDB [(none)]> show full processlist; #查看state慢查询在进行+----+------+-----------+------+---------+------+------------+-----------------------+----------+| Id | User | Host | db | Command | Time | State | Info | Progress |+----+------+-----------+------+---------+------+------------+-----------------------+----------+| 3 | root | localhost | NULL | Query | 9 | User sleep | select sleep(10) | 0.000 || 4 | root | localhost | NULL | Query | 0 | NULL | show full processlist | 0.000 |+----+------+-----------+------+---------+------+------------+-----------------------+----------+2 rows in set (0.00 sec)MariaDB [(none)]> show full processlist; #查看state慢查询已经结束,但是用户登陆了+----+------+-----------+------+---------+------+-------+-----------------------+----------+| Id | User | Host | db | Command | Time | State | Info | Progress |+----+------+-----------+------+---------+------+-------+-----------------------+----------+| 3 | root | localhost | NULL | Sleep | 1 | | NULL | 0.000 || 4 | root | localhost | NULL | Query | 0 | NULL | show full processlist | 0.000 |+----+------+-----------+------+---------+------+-------+-----------------------+----------+2 rows in set (0.00 sec)
希望本文所述对大家MySQL数据库计有所帮助。
更多相关文章
- 《Android和PHP最佳实践》官方站
- android用户界面之按钮(Button)教程实例汇
- TabHost与RadioGroup结合完成的菜单【带效果图】5个Activity
- Android下Excel的操作
- Android(安卓)UI开发第十七篇——Android(安卓)Fragment实例(Lis
- Android——Activity四种启动模式
- 【Android】文件读写操作(含SDCard的读写)
- Android布局(序章)
- Android发送短信方法实例详解