centosmysql磁盘空间,centosmysql占⽤磁盘空间过⼤解决⽅
搜索热词
安装了MysqL以后,过⼀段时间发现磁盘空间不⾜了,查⼀下,发现是mysql-bin.000001、mysql-bin.000002等⽂件占⽤了空间,那么这些⽂件是⼲吗的?这是数据库的操作⽇志,例如UPDATE⼀个表,或者DELETE⼀些数据,即使该语句没有匹配的数据,这个命令也会存储到⽇志⽂件中,还包括每个语句执⾏的时间,也会记录进去的。
这样做主要有以下两个⽬的:
1:数据恢复
如果你的数据库出问题了,⽽你之前有过备份,那么可以看⽇志⽂件,出是哪个命令导致你的数据库出问题了,想办法挽回损失。
2:主从服务器之间同步数据
主服务器上所有的操作都在记录⽇志中,从服务器可以根据该⽇志来进⾏,以确保两个同步。
root@chinaitlabs]# /usr/local/MysqL/bin/MysqL -u root -p
Enter password: (输⼊密码)
Welcome to the MysqL monitor. Commands end with ; or /g.
Your MysqL connection id is @H_403_21@264001
Server version: @H_403_21@5.1.@H_403_21@35-log Source distribution
Type ‘help;’ or ‘/h’ for help. Type ‘/c’ to clear the current input statement.
MysqL> reset master; (清除⽇志⽂件)
Query OK,@H_403_21@0 rows affected (@H_403_21@8.51 sec)
MysqL>
好了,我们再来查看下MysqL⽂件夹占⽤多少空间?
[root# du -h --max-depth=1 /usr/local/MysqL/
mysql下载哪个盘
@H_403_21@37M /usr/local/MysqL/var
@H_403_21@70M /usr/local/MysqL/MysqL-test
@H_403_21@15M /usr/local/MysqL/lib
@H_403_21@448K /usr/local/MysqL/include
@H_403_21@2.9M /usr/local/MysqL/share
@H_403_21@7.6M /usr/local/MysqL/libexec
@H_403_21@17M /usr/local/MysqL/bin
@H_403_21@11M /usr/local/MysqL/docs
@H_403_21@2.9M /usr/local/MysqL/sql-bench
@H_403_21@163M /usr/local/MysqL/
现在看⼀下,整个MysqL ⽬录才占⽤163M⼤⼩!OK,没问题,既然mysql-bin.0000X⽇志⽂件占⽤这么⼤空间,存在的意义⼜不是特别⼤,那么我们就不让它⽣成吧。
@jiucool var]# vi /etc/myf
到了myf 即MysqL配置⽂件,我们将log-bin=MysqL-bin 这条注释掉即可. # Replication Master Server (default)
# binary logging is required for replication
#log-bin=MysqL-bin
重启下MysqL吧。
OK,⾄此,操作完成. 以后再不会因为就⼏⼗M的数据库⼤⼩⽣成N个G的⽇志⽂件。