如何启动MySQL查询日志

如何启动MySQL查询日志,第1张

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_%'查看所有的log命令

②show variables like 'log_bin'查看具体的log命令

查看 <mysql安装目录>/data/**.err 文件中,查找按时间记录的条目,其中有 log sequence number 附近的就是启动日志,之后有 mysqld: ready for connections. 的则为正常启动。

#以下是windows环境,mysql-5.5.22的一个日志。

130412 15:11:10 [Note] Plugin 'FEDERATED' is disabled.

130412 15:11:10 InnoDB: The InnoDB memory heap is disabled

130412 15:11:10 InnoDB: Mutexes and rw_locks use Windows interlocked functions

130412 15:11:10 InnoDB: Compressed tables use zlib 1.2.3

130412 15:11:10 InnoDB: Initializing buffer pool, size = 300.0M

130412 15:11:10 InnoDB: Completed initialization of buffer pool

130412 15:11:10 InnoDB: highest supported file format is Barracuda.

130412 15:11:11 InnoDB: Waiting for the background threads to start

130412 15:11:12 InnoDB: 1.1.8 startedlog sequence number 2039064

130412 15:11:13 [Note] Event Scheduler: Loaded 0 events

130412 15:11:13 [Note] D:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld: ready for connections.

Version: '5.5.22' socket: '' port: 3306 MySQL Community Server (GPL)

mysql有以下几种日志:

错误日志:     -log-err

查询日志:     -log

慢查询日志:   -log-slow-queries

更新日志:     -log-update

二进制日志: -log-bin  

是否启用了日志 

mysql>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下:

Sql代码  

# 在[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

windows下:

Sql代码  

# 在[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  --对所有执行语句进行记录


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/7383740.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-05
下一篇 2023-04-05

发表评论

登录后才能评论

评论列表(0条)

保存