Home > Database > Mysql Tutorial > MySQL 二进制日志删除与恢复

MySQL 二进制日志删除与恢复

WBOY
Release: 2016-06-07 16:57:51
Original
829 people have browsed it

如果不想要这些文件应该怎么做呢? 1:只有一个mysql服务器,那么可以简单的注释掉这个选项就行了。vi /etc/my.cnf把里面的 log-b

vi  /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
# old_passwords=1
table_cache = 300
default-character-set = utf8
log = /var/lib/mysqllog/mysql.log
log-bin = /var/lib/mysqllog/log-bin
log-slow-queries = /var/lib/mysqllog/slowquery.log
long_query_time=2

[mysql.server]
user=mysql
basedir=/var/lib

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
其中黑体的内容为增加的。斜体的log-error=/var/log/mysqld.log原有的
mysql有以下几种日志: 
错误日志:   -log-err  
查询日志:   -log 
慢查询日志:     -log-slow-queries 
更新日志:     -log-update    我的这个版本已经不用了,update的操作也记入查询日志中。设置上后错误日志中会有一条错误信息,不过不影响使用
二进制日志:   -log-bin 


附录:

//显示所有本机上的二进制日志
mysql> SHOW MASTER LOGS;
//删除所有本机上的二进制日志
mysql> RESET MASTER;
//删除所有创建时间在binary-log.xxx之前的二进制日志
mysql> PURGE MASTER LOGS TO 'binary-log.xxx';
//只保留最近6天的日志,之前的都删掉
find /var/intra -type f -mtime +6 -name "*.log" -exec rm -f {} \;
//用键盘左上角(也就是Esc下面)那个键包围起来,说明是命令。-1d是昨天,,以此类推-1m是上个月等等
day=`/bin/date -v -1d +%Y%m%d`;
//给文件改名
mv xxx.log xxx-${day}.log;
//这里还要加上数据库的用户名密码,作用是更新日志(包括二进制日志和查询日志等等)
mysqladmin flush-logs

 

打开mysql的慢查询日志记录

mysql慢查询日志对于跟踪有问题的查询非常有用,可以分析出当前程序里有很耗费资源的sql语句,那如何打开mysql的慢查询日志记录呢?
其实打开mysql的慢查询日志很简单,只需要在mysql的配置文件里(windows系统是my.ini,linux系统是my.cnf)的[mysqld]下面加上如下代码:

log-slow-queries=/var/lib/mysql/slowquery.log
long_query_time=2

linux

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