Mysql日志文件开启、配置、查看
- mysql.log是mysql的日志文件,里面记录的对MySQL数据库的操作记录。默认情况下mysql的日志文件没有产生,需要修改mysql的配置文件,步骤如下:
1. 找到配置文件位置
mysql> show variables like 'datadir';
+---------------+---------------------------------------------+
| Variable_name | Value |
+---------------+---------------------------------------------+
| datadir | C:ProgramDataMySQLMySQL Server 8.0Data |
+---------------+---------------------------------------------+
1 row in set, 1 warning (0.00 sec)
找到:C:ProgramDataMySQLMySQL Server 8.0Datamy.ini
2.查看是否已经打开日志(默认打开)
mysql> show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin | ON |
+---------------+-------+
1 row in set, 1 warning (0.07 sec)
3.打开/关闭日志功能
- 第1步查到的目录,在其中找到my.ini,
- 关闭:加上
skip-log-bin
和disabled-log-bin
即可 - 打开:注释掉
skip-log-bin
和disabled-log-bin
即可
重启mysql服务即生效
windows
net start mysql80
net start mysql
linux
sudo service mysql restart
4. 打开MySQL的日志文件。
日志文件位置可据下推出:
# General and Slow logging.
log-output=FILE
general-log=0
general_log_file="0H6IZJBSR3WV8F7.log"
slow-query-log=1
slow_query_log_file="0H6IZJBSR3WV8F7-slow.log"
long_query_time=10
# Binary Logging.
log-bin="0H6IZJBSR3WV8F7-bin"
# Error Logging.
log-error="0H6IZJBSR3WV8F7.err"
# Server Id.
server-id=1
5. mysql日志文件所在位置:
windows:
C:ProgramDataMySQLMySQL Server 8.0Data H6IZJBSR3WV8F7.log
linux:
/var/log/mysql/mysql.log
5. 使用下面的命令可以实时查看mysql的日志文件:
windows直接打开上步文件即可
sudo tail -f /var/log/mysql/mysql.log