Home > Database > Mysql Tutorial > 记录MySQL执行的SQL_MySQL

记录MySQL执行的SQL_MySQL

WBOY
Release: 2016-06-01 13:01:35
Original
1107 people have browsed it

对比Oracle功能去学习Mysql总会发现亮点

Oracle中通过日志挖掘这一技能,可以找到曾经执行过的所有记录;

Mysql中也提供了3种方法{验证过的,我会记录具体做法}

方法1:{已验证}

记录MySQL的所有记录
打开/etc/my.cnf
在[mysqld]下面加入
log = /mnt/mydata/sql.log

重启mysql即可

查看/mnt/mydata/sql.log文件

注意:

1.因为sql.log会因为有大量的写入,注意监控IO和sql.log的大小;

2.调试或者查询完成后,建议关闭改功能


方法2:{暂时未验证}

查Slow query的SQL语法:
log_slow_queries = /var/log/mysql/mysql-slow.log
long_query_time = 2 (超过2秒的SQL语法记录起来,设短一点来记录除错也是一种方法.)

方法3:{暂时未验证}

设MySQL Replication用binlog:

log_bin = /var/log/mysql/mysql-bin.log (此档要用mysqlbinlog解来看,
mysqlbinlog mysql-bin.000042| grep "T_ABC" | grep "column value"
mysql会将所有INSERT/UPDATE/DELETE语法记于此(但是语法可能跟你想的不同),这是要写给SLAVE用的log 文件

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template