這篇文章將為大家詳細講解有關(guān)如何在線安全清空慢查詢?nèi)罩緎lowlog,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
成都創(chuàng)新互聯(lián)公司是網(wǎng)站建設(shè)技術(shù)企業(yè),為成都企業(yè)提供專業(yè)的網(wǎng)站設(shè)計、成都網(wǎng)站設(shè)計,網(wǎng)站設(shè)計,網(wǎng)站制作,網(wǎng)站改版等技術(shù)服務(wù)。擁有十余年豐富建站經(jīng)驗和眾多成功案例,為您定制適合企業(yè)的網(wǎng)站。十余年品質(zhì),值得信賴!
MySQL> show variables like '%slow_query%';
+------------------------------------+-------------------------------+
| Variable_name | Value |
+------------------------------------+-------------------------------+
| slow_query_log | ON |
| slow_query_log_always_write_time | 10.000000 |
| slow_query_log_file | /data/DB/mysql/mysql-slow.log |
| slow_query_log_timestamp_always | OFF |
| slow_query_log_timestamp_precision | second |
| slow_query_log_use_global_control | |
+------------------------------------+-------------------------------+
[root@trcloud-gtt-dw backup]# ls -l /data/DB/mysql/mysql-slow.log
-rw-rw---- 1 mysql mysql 2482474901 Jun 24 14:47 /data/DB/mysql/mysql-slow.log
發(fā)現(xiàn)慢查詢?nèi)罩疽呀?jīng)有2G多了,使用mysqldumpslow統(tǒng)計信息的時候非常慢,需要在線清空并備份
一:關(guān)閉慢查詢?nèi)罩?br/>mysql> set global slow_query_log=0;
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like '%slow_query%';
+------------------------------------+-------------------------------+
| Variable_name | Value |
+------------------------------------+-------------------------------+
| slow_query_log | OFF |
| slow_query_log_always_write_time | 10.000000 |
| slow_query_log_file | /data/DB/mysql/mysql-slow.log |
| slow_query_log_timestamp_always | OFF |
| slow_query_log_timestamp_precision | second |
| slow_query_log_use_global_control | |
+------------------------------------+-------------------------------+
6 rows in set (0.00 sec)
二:指定新的慢查詢?nèi)罩疚募?br/>mysql> set global slow_query_log_file='/data/DB/mysql/mysql-slow_20160624.log';
Query OK, 0 rows affected (0.00 sec)
三:開啟慢查詢?nèi)罩?br/>mysql> set global slow_query_log=1;
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like '%slow_query%';
+------------------------------------+----------------------------------------+
| Variable_name | Value |
+------------------------------------+----------------------------------------+
| slow_query_log | ON |
| slow_query_log_always_write_time | 10.000000 |
| slow_query_log_file | /data/DB/mysql/mysql-slow_20160624.log |
| slow_query_log_timestamp_always | OFF |
| slow_query_log_timestamp_precision | second |
| slow_query_log_use_global_control | |
+------------------------------------+----------------------------------------+
6 rows in set (0.00 sec)
查看信息的慢查詢?nèi)罩疚募?br/>[root@trcloud-gtt-dw backup]# tail -50f /data/DB/mysql/mysql-slow_20160624.log
# Time: 160624 15:13:28
# User@Host: admin[admin] @ [172.30.250.103] Id: 20178
# Schema: gtt_api Last_errno: 0 Killed: 0
# Query_time: 0.000163 Lock_time: 0.000080 Rows_sent: 1 Rows_examined: 1 Rows_affected: 0
# Bytes_sent: 618
SET timestamp=1466752408;
SELECT invest_money, total_earning, invest_this_month, invest_last_month, total_wait_earning, total_people FROM th_home_data;
已經(jīng)開始記錄慢查詢?nèi)罩?br/>
四:備份老的慢查詢?nèi)罩疚募?br/>
[root@trcloud-gtt-dw backup]# mv /data/DB/mysql/mysql-slow.log /backup/mysql-slow.log.bak.20160624
關(guān)于“如何在線安全清空慢查詢?nèi)罩緎lowlog”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。