mysql日志,Mysql开启日志

是否启用了日志
mysql>show variables like 'log_bin';
怎样知道当前的日志
mysql> show master status;
看二进制日志文件用mysqlbinlog
shell>mysqlbinlog mail-bin.000001(要写绝对问题路径 d://)
或者shell>mysqlbinlog mail-bin.000001 | tail
mysql有以下几种日志:
错误日志: -log-err
查询日志: -log
慢查询日志: -log-slow-queries
更新日志: -log-update
二进制日志: -log-bin
mysql的安装目录下,打开my.ini,在后面加上上面的参数,保存后重启mysql服务就行了。
例如:
#Enter a name for the error log file. Otherwise a default name will be used.
log-error=err.log
#Enter a name for the query log file. Otherwise a default name will be used.
#log=
#Enter a name for the slow query log file. Otherwise a default name will be used.
#log-slow-queries=
#Enter a name for the update log file. Otherwise a default name will be used.
#log-update=
#Enter a name for the binary log. Otherwise a default name will be used.
#log-bin=
上面只开启了错误日志,要开其他的日志就把前面的“#”去掉。
long_query_time =1 --是指执行超过多久的sql会被log下来,这里是1秒
log-slow-queries=slowqueris.log --将查询返回较慢的语句进行记录
log-queries-not-using-indexes = nouseindex.log --就是字面意思,log下来没有使用索引的query
log=mylog.log --对所有执行语句进行记录
log-error=log-error.log
log=log-query.log
log-queries-not-using-indexes
log-warnings=2
log-slow-queries=log-slow-query.log
log-update=log-update.log
long_query_time=2
1. 指定恢復時間語法
假如你今天早上9點不小心砍掉哪個資料庫的資料表,你可以利用下面語法來恢復
mysqlbinlog --stop-date="2007-03-29 8:59:59" /var/lib/mysql/bin.000001 | mysql -u root -p
如果你想恢復後面9點以後sql語法 可以使用
mysqlbinlog --start-date="2007-03-29 9:00:00" /var/lib/mysql/bin.000001 | mysql -u root -p
或者是 你想恢復 9點到10點之間的sql語法,則下面語法是您想要的
mysqlbinlog --start-date="2007-03-29 9:00:00" --stop-date="2007-03-29 10:00:00" /var/lib/mysql/bin.000001 | mysql -u root -p
其實你也可以不要執行,先把sql語法輸出到 /tmp/restore.sql
mysqlbinlog --start-date="2007-03-29 9:00:00" --stop-date="2007-03-29 10:00:00" /var/lib/mysql/bin.000001 > /tmp/restore.sql
當然 你也可以指定你要輸出的 database,免的檔案很大
--database=db_name,-d db_name
--host=host_name,-h host_name
Tags: 

延伸阅读

最新评论

发表评论