MySQL錯誤日誌是記錄MySQL 運行過程當中較爲嚴重的警告和錯誤信息,以及MySQL每次啓動和關閉的詳細信息。錯誤日誌的命名一般爲hostname.err。其中,hostname表示服務器主機名。 mysql
The error log contains information indicating when mysqld was started and stopped and also any critical errors that occur while the server is running. If mysqld notices a table that needs to be automatically checked or repaired, it writes a message to the error log. On some operating systems, the error log contains a stack trace if mysqld exits abnormally. The trace can be used to determine where mysqld exited. See Section 24.5, 「Debugging and Porting MySQL」.sql
查看錯誤日誌的位置 shell
錯誤日誌默認存放位置爲數據目錄下,你也能夠用下面命令查看。例以下面是我測試服務的狀況。服務器
mysql> show variables like '%log_error%';
+---------------+------------------------------------------------------+
| Variable_name | Value |
+---------------+------------------------------------------------------+
| log_error | /home/WDPM/MysqlData/mysql/DB-Server.localdomain.err |
+---------------+------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
修改錯誤日誌的位置 app
錯誤日誌所記錄的信息是能夠經過log-error和log-warnings來定義的,其中log_error是定義是否啓用錯誤日誌的功能和錯誤日誌的存儲位置,log-warnings是定義是否將警告信息也定義至錯誤日誌中。能夠在啓動MySQL時,指定log_error的值。以下所示dom
[root@DB-Server ~]# /etc/init.d/mysql start --log_error=/tmp/DB-Server.localdomain.err
Starting MySQL..........[ OK ]
[root@DB-Server ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.20-enterprise-commercial-advanced-log MySQL Enterprise Server - Advanced Edition (Commercial)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show variables like '%log_error%';
+---------------+--------------------------------+
| Variable_name | Value |
+---------------+--------------------------------+
| log_error | /tmp/DB-Server.localdomain.err |
+---------------+--------------------------------+
1 row in set (0.00 sec)
若是關閉MySQL,而後重啓MySQL,你會發現log_error的值又變爲了/home/WDPM/MysqlData/mysql/DB-Server.localdomain.err 。也就是說這樣設置只是對本次有效,若是須要永久修改,那麼就必須在my.cnf中指定log_error參數的值。 測試
錯誤日誌能夠任意命名嗎? 答案是能夠,例如我在/etc/my.cnf配置文件中,添加了參數log_error=/u02/mysql/mysql.err,從新啓動MySQL,以下所示 spa
若是配置文件中設置了參數log_error,啓動MySQL時也設置參數log_error,那麼那個優先級高呢?我測試驗證了一下,my.cnf的參數優先級別要高於啓動是的參數log_error 日誌
/etc/init.d/mysql start log_error=/tmp/DB-Server.localdomain.err code
錯誤日誌歸檔備份
錯誤日誌若是不清理或刪除,那麼它會一直增加。在MySQL 5.5.7以前,能夠經過mysqladmin –uroot –p flush-logs命令刪除錯誤日誌。MySQL 5.5.7以及以後,只能經過下面方式來歸檔、備份錯誤日誌.
shell> mv host_name.err host_name.err-old
shell> mysqladmin -u root -p flush-logs
shell> mv host_name.err-old backup-directory