mysql啟用日志和查看日志


mysql有以下幾種日志:
錯誤日志: -log-err
查詢日志: -log
慢查詢日志: -log-slow-queries
更新日志: -log-update
二進制日志: -log-bin

在mysql的安裝目錄下,打開my.ini,在后面加上上面的參數,保存后重啟mysql服務就行了。
例如:
#Enter a name for the binary log. Otherwise a default name will be used.
#log-bin=#Enter a name for the query log file. Otherwise a default name will be used.
#log=#Enter a name for the error log file. Otherwise a default name will be used.
log-error=#Enter a name for the update log file. Otherwise a default name will be used.
#log-update=


是否啟用了日志
show variables like 'log_%';
怎樣知道當前的日志
mysql> show master status;
顯示二進制日志數目
mysql> show master logs;

看二進制日志文件用mysqlbinlog
shell>mysqlbinlog mail-bin.000001
或者shell>mysqlbinlog mail-bin.000001 | tail

在配置文件中指定log的輸出位置.
Windows:Windows 的配置文件為 my.ini,一般在 MySQL 的安裝目錄下或者 c:\Windows 下。

Linux:Linux 的配置文件為 my.cnf ,一般在 /etc 下。

Linux下:
# 在[mysqld] 中輸入
#log
log-error=/usr/local/mysql/log/error.log
log=/usr/local/mysql/log/mysql.log
long_query_time=2
log-slow-queries= /usr/local/mysql/log/slowquery.log
window下
# 在[mysqld] 中輸入
#log
log-error="E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/error.log"
log="E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/mysql.log"
long_query_time=2
log-slow-queries= "E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/slowquery.log"

開啟慢查詢
long_query_time =2 --是指執行超過多久的sql會被log下來,這里是2秒
log-slow-queries= /usr/local/mysql/log/slowquery.log --將查詢返回較慢的語句進行記錄
log-queries-not-using-indexes = nouseindex.log --就是字面意思,log下來沒有使用索引的query
log=mylog.log --對所有執行語句進行記錄

原文:http://blog.csdn.net/a351945755/article/details/28239819


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM