Mysql Data directory and Binlog directory relocation methods

  • 2020-05-12 06:20:04
  • OfStack

If you are using an Mysql user, you should be able to boot normally.
If you are using an ROOT user, you may not be able to start properly because the new directory has the wrong permissions.
You might get an error like this:
/ usr/local/mysql/libexec/mysqld: File '/ home mysql/mysqllog binlog/mysql - bin. index' not found (Errcode: 2)

It is very important that you stop stop mysql service 1 first.
# /etc/init.d/mysqld stop
2. Modify Mysql configuration My.cnf:

#datadir = /usr/local/mysql/var
#log-bin = /usr/local/mysql/var/binlog/mysql-bin

datadir = /home/mysql/mysqldata
log-bin = /home/mysql/mysqllog/binlog/mysql-bin

3. copy mysql data
# cp -rf /usr/local/mysql/var/* /home/mysql/mysqldata/

4. start mysql service
# /etc/init.d/mysqld start

If the entire process is using Mysql users, it should start normally.
If you are using an ROOT user, you may not be able to start properly because the new directory has the wrong permissions.
Use the following command to modify it:
# chown mysql:mysql /home/mysql -R

Note the following modifications if Innodb is used:

innodb_data_home_dir = /home/mysql/mysqldata/
innodb_log_group_home_dir = /home/mysql/mysqldata/

Related articles: