How to change MySQL binlogs files location

Configuring/change MySQL bin-logs files location

Many of you maybe have faced the problem with growing size of their database and desperate need of storage on the partition where MySQL database is located.

  • 1- Make a full backup of your database
  • 2- Shutdown your mysql server.
  • [root@xxxx2 mysql]# /etc/init.d/mysqld stop
    Stopping mysqld:                                           [  OK  ]
  • 3- Create/Choose the new location where the file will be written and make sure is owned by the mysql user and mysql group. In our case the new location will be "/home/mysql_dados/xxxx2_bin_logs/"
  • 4- Edit you my.cnf file and add under [mysqld] the new "log-bin" path value.
  •  log-bin=/home/mysql_dados/xxxx2_bin_logs
  • 5- Relocate all bin-log files including the index file to the new locations keeping the original file permissions.
  • [root@xxxx2 mysql_dados]# cp mysql-bin.* /home/mysql_dados/xxxx2_bin_logs
  • 6- Start your server now.
  • [root@xxxx2 mysql_dados]# /etc/init.d/mysqld start
    Starting mysqld:                                           [  OK  ]