Mysql -- slow query log

Source: Internet
Author: User

Recently, mysql managed by myself experienced slow query. In order to be able to query slow query SQL statements, mysql's slow query log is started, you can use either of the following methods to start a slow query:
1. log on to mysql directly and change mysql parameters. (Note: You must have the administrator privilege to log on to the account)
Mysql> set global log_slow_queries = on;
Mysql> set global slow_query_log_file =/data/mysql. slow. log;
Mysql> set global long_query_time = 1;
If this method is used, it will not take effect after the database is restarted.
2. directly change my. conf
[Mysqld]
Log-slow-queries =/data/mysql. slow. log
Long_query_time = 1
I used 2nd methods this time, but after I restarted mysql, I found that the slow query log did not take effect. I queried the mysql Log and found that the log reported the following error:
110907 18:28:04 InnoDB: Started; log sequence number 0 4245951191
/Usr/libexec/mysqld: File '/data/mysql. slow. log' not found (Errcode: 13)
110907 18:28:04 [ERROR] cocould not use/data/mysql. slow. log for logging (error 13 ). turning logging off for the whole duration of the MySQL server process. to turn it on again: fix the cause, shutdown the MySQL server and restart it.
In this case, you can solve the problem by performing the following operations:
Touch/data/mysql. slow. log
Chown mysql. mysql/data/mysql. slow. log
Chmod o-r/data/mysql. slow. log
However, it still does not work. I analyzed the log again and found that it was mainly/data/mysql. slow. the log file cannot be found, but in fact/data/mysql. slow. log File is there; there is no way to suddenly did not find the cause, first change the slow Query file path to/var/log/mysql-slow.log try, this way.
110907 18:39:57 mysqld_safe mysqld from pid file/var/run/mysqld. pid ended
110907 18:39:57 mysqld_safe Starting mysqld daemon with databases from/var/lib/mysql
110907 18:39:57 [Warning] '-- log_slow_queries' is deprecated and will be removed in a future release. Please use ''-- slow_query_log '/' -- slow_query_log_file'' instead.
110907 18:39:57 InnoDB: Started; log sequence number 0 4245951191
110907 18:39:57 [Note] Event schedents: Loaded 0 events
110907 18:39:57 [Note]/usr/libexec/mysqld: ready for connections.
Version: '5. 1.52-log' socket: '/var/lib/mysql. sock' port: 3306 Source distribution
[Root @ localhost log] # ll | grep mysql
-Rw-r -----. 1 mysql 512181 Sep 7 mysqld. log
-Rw-r --. 1 mysql 422 Sep 7 mysql-slow.log
[Root @ localhost log] # cat mysql-slow.log
/Usr/libexec/mysqld, Version: 5.1.52-log (Source distribution). started:
Tcp port: 0 Unix socket:/var/lib/mysql. sock
Time Id Command Argument
# Time: 110907 18:41:29
# User @ Host: root [root] @ localhost []
# Query_time: 1.512086 FIG: 0.000001 Rows_sent: 26 Rows_examined: 2443129
Use idmanage;
SET timestamp = 1315392089;
Select type, count (*) from client where status = 1 group by type;
The reason should be: mysql does not seem to support data writing across hard disks.
My actual situation is like this. I used to have insufficient space. Then I hung up a hard disk and mounted the new hard disk to/data.
[Root @ localhost log] # df-h
Filesystem Size Used Avail Use % Mounted on
/Dev/mapper/VolGroup-lv_root
7.0G 6.6G 12 M 100%/
Tmpfs 250 M 0 250 M 0%/dev/shm
/Dev/sda1 485 M 29 M 432 M 7%/boot
/Dev/mapper/VolGroup-lv_file
485 M 11 M 449 M 3%/file
/Dev/sdb1 9.9G 8.1G 1.3G 87%/data
 
Author "Flying"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.