17
[root@jiaoyou mysql]# pwd
/var/lib/mysql
[root@jiaoyou mysql]# ls -ls
338256 -rw-rw---- 1 mysql mysql 346030080 2010-04-22 08:08 ibdata1
626812 -rw-rw---- 1 mysql mysql 641222072 2010-01-26 07:17 mysql-bin.000008
316892 -rw-rw---- 1 mysql mysql 324173772 2010-03-25 12:51 mysql-bin.000009
52724 -rw-rw---- 1 mysql mysql  53931666 2010-04-12 12:13 mysql-bin.000010
10136 -rw-rw---- 1 mysql mysql  10359639 2010-04-22 08:32 mysql-bin.000011

mysql> SHOW BINARY LOGS; 
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000008 | 641222072 | 
| mysql-bin.000009 | 324173772 | 
| mysql-bin.000010 |  53931666 | 
| mysql-bin.000011 |  10360680 | 
+------------------+-----------+

These files ibdata1,mysql-bin.000008 and mysql-bin.000009 ... are taking up too much of my space,will it be ok for me to delete some of them manually?

UPDATE I'm not utilizing MySQL's master/slave,how to drop and disable all the binary files?

2
  • SHOW BINARY LOGS; may return an error message like "Error 1381: You are not using binary logging".
    – bronze man
    Commented Jul 12, 2019 at 1:20
  • If you do receive the Error 1381: You are not using binary logging message, what does that mean? Is it then safe to manually delete the files?
    – Dan J.
    Commented Jan 10, 2020 at 18:50

4 Answers 4

13

Those are mysql bin logs. The server can get seriously irritated if you delete them with rm.

Instead, use PURGE BINARY LOGS TO 'mysql-bin.010'; as the root mysql user to let it safely delete the files.

More information can be found here in the documentation.

2
  • What's the relation between these BINARY LOGS?
    – apache
    Commented Apr 22, 2010 at 13:34
  • These are the files that are in your database /var/lib/mysql directory. Commented Apr 22, 2010 at 15:53
7

These are the logs files for mysql service. The setting can be customized by updating /etc/my.cnf file

If they are eating up your disk space then add the setting to auto clear logs based on number of days you want to keep

For e.g. below setting will delete all logs older than 90 days

**expire_logs_days=100**

to reflect this setting we need to restart the mysql service

/etc/init.d/mysql restart

Hope this helps

4
  • This is the most durable solution. Also the easiest way to purge if you don't quite remember your MySQL passwords :-)
    – kasimir
    Commented Jun 27, 2019 at 7:05
  • Best solution ever! If you want to purge all files, just set to 0 days, and then back to a good value based on your application. Thanks, pal! Commented Dec 1, 2019 at 6:31
  • 1
    Use binlog_expire_logs_seconds to set the expire time (expire_logs_days is deprecated) mysql> SET GLOBAL binlog_expire_logs_seconds = 604800;
    – hoppy
    Commented May 17, 2021 at 22:40
  • my.cnf file was in /etc/mysql/my.cnf
    – Jordan
    Commented Jan 10, 2023 at 18:07
5

The mysql-bin files are the binary logs, which are typically both for either a transaction history or for the purpose of replication. To disable binary logging, you can comment the log-bin* lines in the cnf. log-slave-updates should be commented too if enabled.

ibdata* files are part of InnoDB's tablespace, which is specified with the innodb_data_file_path setting. I wouldn't recommend deleting unless you have no InnoDB tables and first disable InnoDB by using skip-innodb in the cnf.

2
  • Do I need to comment the server-id to disable it?
    – apache
    Commented Apr 22, 2010 at 15:03
  • No, you do not but you could. That is used for identifying the server uniquely during replication.
    – Warner
    Commented Apr 22, 2010 at 15:48
1

To disable the logging entirely you need to comment out the log-bin value in your config file (typically /etc/my.cnf):

#log-bin = /var/log/mysql/mysql-bin.log

I think the ibdata1 file might contain the actual database though - I don't use innodb so I'm not sure - and so I would not recommend removing that one. The "PURGE BINARY LOGS TO..." command will get rid of the binary logs though.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .