在Debian系統上,您可以使用以下方法查看MySQL日志:
journalctl
命令(適用于使用systemd的系統):sudo journalctl -u mysql.service
這將顯示MySQL服務的所有日志。您可以使用-b
選項查看上次啟動的日志,或者使用-e
選項僅查看錯誤日志。
默認情況下,MySQL錯誤日志位于/var/log/mysql/error.log
。您可以使用cat
、less
或tail
等命令查看日志:
sudo cat /var/log/mysql/error.log
或者
sudo less /var/log/mysql/error.log
要實時查看日志更新,可以使用tail
命令:
sudo tail -f /var/log/mysql/error.log
如果您啟用了MySQL通用查詢日志,它通常位于/var/log/mysql/mysql.log
。您可以使用與查看錯誤日志相同的方法查看此日志:
sudo cat /var/log/mysql/mysql.log
或者
sudo less /var/log/mysql/mysql.log
或者
sudo tail -f /var/log/mysql/mysql.log
注意:您可能需要根據MySQL配置文件(通常位于/etc/mysql/my.cnf
或/etc/mysql/mysql.conf.d/mysqld.cnf
)中的設置來查找正確的日志文件路徑。在配置文件中,檢查log_error
(用于錯誤日志)和general_log_file
(用于通用查詢日志)設置。