Home >Database >Mysql Tutorial >mysql――slow query log_MySQL

mysql――slow query log_MySQL

WBOY
WBOYOriginal
2016-06-01 13:45:111168browse

bitsCN.com

由于最近自己管理的mysql有出现查询慢的情况,为了能够查询出慢查询的sql语句,故启动了mysql的慢查询日志,具体启动慢查询的方法有以下两种:
1、直接登入mysql, 更改mysql参数.(注:登入账号需有管理员权限)
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;
如果是这种方法的话,重启数据库之后就不生效了。
2、直接更改my.conf
[mysqld]
log-slow-queries = /data/mysql.slow.log
long_query_time = 1
我本次使用的是第2种方法,但是重启mysql之后发现慢查询日志没有生效,查询了一下mysql日志,发现日志报如下错误:
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] Could 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.
出现这个情况,一般通过以下操作就可以解决:
touch /data/mysql.slow.log
chown mysql.mysql /data/mysql.slow.log
chmod o-r /data/mysql.slow.log
可是还是不行,再次认真分析了下log发现主要还是/data/mysql.slow.log文件无法找到引起的,但是实际上/data/mysql.slow.log文件是存在的;没办法一下子没找到原因,先把慢查询文件路径改为/var/log/mysql-slow.log试试,这样就行了。
110907 18:39:57 mysqld_safe mysqld from pid file /var/run/mysqld/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 Scheduler: Loaded 0 events
110907 18:39:57 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.52-log'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution
[root@localhost log]# ll |grep mysql
-rw-r-----. 1 mysql mysql 512181 Sep  7 18:39 mysqld.log
-rw-r--r--. 1 mysql mysql    422 Sep  7 18:41 mysql-slow.log
[root@localhost log]# cat  mysql-slow.log
/usr/libexec/mysqld, Version: 5.1.52-log (Source distribution). started with:
Tcp port: 0  Unix socket: /var/lib/mysql/mysql.sock
Time                 Id Command    Argument
# Time: 110907 18:41:29
# User@Host: root[root] @ localhost []
# Query_time: 1.512086  Lock_time: 0.000001 Rows_sent: 26  Rows_examined: 2443129
use idmanage;
SET timestamp=1315392089;
select type,count(*) from client where status=1 group by type;
经过自己的分析原因应该是:mysql好像不支持跨硬盘写数据。
我的实际情况是这样的,我以前的空间不够用了,然后我再挂了一块硬盘进去了,且新硬盘mount的路径就是/data。
[root@localhost log]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      7.0G  6.6G   12M 100% /
tmpfs                 250M     0  250M   0% /dev/shm
/dev/sda1             485M   29M  432M   7% /boot
/dev/mapper/VolGroup-lv_file
                      485M   11M  449M   3% /file
/dev/sdb1             9.9G  8.1G  1.3G  87% /data
 
作者“飞扬”

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn