MySQL can record all slow queries and record the SQL statements in the specified file, or you can add updates through the Mysqlbinlog record, or you can restore the database through Mysqlbinlog.
MySQL Slow query record
Edit My.cnf File
Linux is usually in/etc/my.cnf or/usr/local/mysql/etc/my.cnf
Windows find it Yourself
In the [Mysqld] tab, add the following:
The code is as follows |
Copy Code |
Log-slow-queries=/var/lib/mysql/slow.log #慢日志保存路径, the file itself new long_query_time=2 #超过2秒的查询 ; Log-queries-not-using-indexes #记录没有使用索引的查询 |
Turn on MySQL incremental logging
Also add the following in the [Mysqld] label below
The code is as follows |
Copy Code |
log-bin=mysqlbin# name to pick Binlog_cache_size = 4M Binlog_format = MIXED Max_binlog_cache_size = 256M Max_binlog_size = 1g# log size expire_logs_days = 30# Record 30 days of log Mysqlbinlog's log is usually in/var/lib/mysql. |
Log some simple query export operations, where mysqlbin.000001 is a log file inside
The code is as follows |
Copy Code |
Mysqlbinlog--start-datetime= "2013-09-10 00:00:00"--stop-datetime= "2013-09-13 23:59:59" mysqlbin.000001 >/root/ Log.txt |
You can also use these records for database restore