【MySQL】Can't get stat of './mysql/slow_log.CSV' (Errcode: 2)
在給資料庫開啟慢日誌查詢的時候遇到 如下問題
root@rac1 : (none) 23:39:53> set global slow_query_log = 1;
ERROR 13 (HY000): Can't get stat of './mysql/slow_log.CSV' (Errcode: 2)
原因是因為資料庫中沒有slow_log表對應的物理檔案,解決的方法有如下兩種:
方法一 手工建立slow_log.CSV
[root@rac1 mysql]# touch slow_log.CSV
[root@rac1 mysql]# chown -R mysql:mysql slow_log.CSV
[root@rac1 mysql]# chmod 660 slow_log.CSV
root@rac1 : (none) 23:42:36>set global slow_query_log = 1;
Query OK, 0 rows affected, 1 warning (0.17 sec)
root@rac1 : (none) 23:43:03>show warnings;
+-------+------+--------------------------------------------------------------+
| Level | Code | Message |
+-------+------+--------------------------------------------------------------+
| Error | 1194 | Table 'slow_log' is marked as crashed and should be repaired |
+-------+------+--------------------------------------------------------------+
1 row in set (0.00 sec)
root@rac1 : (none) 23:48:03>repair table mysql.slow_log;
+----------------+--------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+----------------+--------+----------+----------+
| mysql.slow_log | repair | status | OK |
+----------------+--------+----------+----------+
1 row in set (0.61 sec)
root@rac1 : (none) 23:51:03>set global slow_query_log = 1;
Query OK, 0 rows affected (0.00 sec)
方法二 在資料庫中以重建表的方式 (個人比較推薦第二種方式)
[root@rac1 ~]# mysql
root@rac1 : (none) 21:47:46>
root@rac1 : (none) 21:47:47> show global variables like '%slow%';
+---------------------+----------------+
| Variable_name | Value |
+---------------------+----------------+
| log_slow_queries | ON |
| slow_launch_time | 2 |
| slow_query_log | ON |
| slow_query_log_file | slow_query.log |
+---------------------+----------------+
4 rows in set (0.06 sec)
root@rac1 : (none) 21:48:19> set global slow_query_log=off;
Query OK, 0 rows affected (0.00 sec)
root@rac1 : (none) 21:48:47>
root@rac1 : (none) 21:48:47> show global variables like '%slow%';
+---------------------+----------------+
| Variable_name | Value |
+---------------------+----------------+
| log_slow_queries | OFF |
| slow_launch_time | 2 |
| slow_query_log | OFF |
| slow_query_log_file | slow_query.log |
+---------------------+----------------+
4 rows in set (0.01 sec)
root@rac1 : (none) 21:48:49> show global variables like '%slow%';
+---------------------+----------------+
| Variable_name | Value |
+---------------------+----------------+
| log_slow_queries | OFF |
| slow_launch_time | 2 |
| slow_query_log | OFF |
| slow_query_log_file | slow_query.log |
+---------------------+----------------+
4 rows in set (0.00 sec)
root@rac1 : (none) 21:49:50> set global slow_query_log=on;
ERROR 13 (HY000): Can't get stat of './mysql/slow_log.CSV' (Errcode: 2)
root@rac1 : mysql 21:50:33> show create table slow_log;
ERROR 13 (HY000): Can't get stat of './mysql/slow_log.CSV' (Errcode: 2)
從一個有slow_log 的資料庫中檢視slow_log的表建立ddl 語句,進行建立!
root@rac1 : mysql 21:51:23> CREATE TABLE `slow_log` (
-> `start_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
-> `user_host` mediumtext NOT NULL,
-> `query_time` time NOT NULL,
-> `lock_time` time NOT NULL,
-> `rows_sent` int(11) NOT NULL,
-> `rows_examined` int(11) NOT NULL,
-> `db` varchar(512) NOT NULL,
-> `last_insert_id` int(11) NOT NULL,
-> `insert_id` int(11) NOT NULL,
-> `server_id` int(10) unsigned NOT NULL,
-> `sql_text` mediumtext NOT NULL
-> ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Slow log';
Query OK, 0 rows affected (0.04 sec)
root@rac1 : mysql 21:51:43>
root@rac1 : mysql 21:51:55> set global slow_query_log=on;
Query OK, 0 rows affected (0.00 sec)
root@rac1 : mysql 21:52:13>
root@rac1 : mysql 21:52:13> show global variables like '%out%';
+----------------------------+----------+
| Variable_name | Value |
+----------------------------+----------+
| log_output | FILE |
+----------------------------+----------+
11 rows in set (0.00 sec)
root@rac1 : mysql 21:52:20> set global log_output = 'TABLE';
Query OK, 0 rows affected (0.00 sec)
root@rac1 : mysql 21:52:41> show global variables like '%out%';
+----------------------------+----------+
| Variable_name | Value |
+----------------------------+----------+
| log_output | TABLE |
+----------------------------+----------+
11 rows in set (0.00 sec)
如果log_output 用TABLE形式記錄日誌,mysql會以表的形式將slow_log存入mysql表中的slow_log表中。
root@rac1 : mysql 21:52:43> select sleep(60);
+-----------+
| sleep(60) |
+-----------+
| 0 |
+-----------+
1 row in set (1 min 0.00 sec)
root@rac1 : mysql 21:54:01> select * from slow_log \G
*************************** 1. row ***************************
start_time: 2012-08-24 21:54:01
user_host: root[root] @ localhost [127.0.0.1]
query_time: 00:01:00
lock_time: 00:00:00
rows_sent: 1
rows_examined: 0
db: mysql
last_insert_id: 0
insert_id: 0
server_id: 1
sql_text: select sleep(60)
1 row in set (0.00 sec)
root@rac1 : mysql 21:57:53>
root@rac1 : mysql 21:58:25> set global log_output = 'FILE';
Query OK, 0 rows affected (0.00 sec)
root@rac1 : mysql 21:58:30> select sleep(10);
+-----------+
| sleep(10) |
+-----------+
| 0 |
+-----------+
1 row in set (10.00 sec)
由於log_output 用FILE形式記錄日誌,所以我們在vim /home/mysql/log/mysql-slow.log 將會看到執行超過0秒的所有的sql
-bash-3.2$ tail -f slow_query.log
Tcp port: 3306 Unix socket: /tmp/mysql.sock
Time Id Command Argument
# Time: 120824 21:58:48
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 10.001827 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
use mysql;
SET timestamp=1345816728;
select sleep(10);
至此問題完全得到解決。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-741767/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysqld: Can‘t create directory ‘E:\Software\mysql-5.7.24-winx64\data\‘ (Errcode: 2 - NoMySql
- MySQL 5.7向表匯入資料包錯"ERROR 13 (HY000): Can't get stat of"MySqlError
- MySQL錯誤1042-Can't get hostname for your addressMySql
- 解決Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2) "MySqlServer
- [ERROR] Can't open the mysql.plugin tableErrorMySqlPlugin
- mysql遇到Variable can’t be set to the value of ‘NULL’MySqlNull
- mysql can't start dues to the disk space is fullMySql
- MySQL錯誤1042-Can't get hostname for your address解決方法MySql
- mysql [ERROR] Can't create IP socket: Permission deniedMySqlError
- MySQL連線提示Can't connect to local MySQL server through socketMySqlServer
- Can't connect to local MySQL server through socket '/tmp/mysql.sock'MySqlServer
- 連線MySQL錯誤:Can't connect to MySQL server (10060)MySqlServer
- MySQL 2003 - Can’t connect to MySQL server on (10060)MySqlServer
- Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock錯誤MySqlServer
- mysql中You can’t specify target table for update in FROM clMySql
- Mysql報錯Fatal error:Can't open and lock privilege tablesMySqlError
- MySQL不能啟動 Can't start server : Bind on unix sockeMySqlServer
- mysql can't connect error about privilege----not root userMySqlError
- Can'tconnecttolocalMySQLserverthroughsocket'/var/lib/mysql/mysql.sock'(2)MySqlServer
- mysql 啟動報錯Can't connect to local MySQL server through socket '/data/mysql/mysql/mysql.sock'(111)MySqlServer
- error:'Can'tconnecttolocalMySQLserverthroughsocket'/var/lib/mysql/mysql.sock'(2)'ErrorMySqlServer
- 異常:Can't connect to MySQL server (10060)MySqlServer
- mysql報CanMySql
- MySQL報錯Table 'plugin' is read only [ERROR] Can't open the mysql.plugin table.MySqlPluginError
- multiprocessing pool AttributeError: Can't get attribute 'func'Error
- Mysql:Variable 'XXXt' can't be set to the value of 'NULL'解決MySqlNull
- MySQL 建立外來鍵報錯Can't write; duplicate key in tableMySql
- MySQL 5.5 原始碼安裝報錯"[ERROR] Can't start server"MySql原始碼ErrorServer
- mysql:Variable 'character_set_client' can't be set to the value of 'NULL'解決MySqlclientNull
- MySQL 5.5 關閉資料庫報錯"Can't connect to local MySQL server through socket"MySql資料庫Server
- Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)解決方法MySqlServer
- MySQL問題記錄--Can't connect to MySQL server on localhost (10061)解決方法MySqlServerlocalhost
- MySQL報錯'ERROR 2002 (HY000): Can't connect to local MySQL server through'MySqlErrorServer
- ERROR 2002(HY000):Can't connect to local MySQL socket '/tmp/mysql.sock'ErrorMySql
- MYSQL報1022錯誤:Can't write;duplicate key in table '.....'MySql
- Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist解決辦法ErrorMySql
- [Oracle] crsctl stat res -tOracle
- MySQL案例-不同尋常的[ERROR]Can't create a new thread (errno 11)MySqlErrorthread