Steps to change the mysql database directory in Linux server

Some times the ‘/var’ partition get crowded and we might need to relocate the database to some other location where there is enough space. Below are the steps given for a trouble free relocation.

Note: Let ‘/test/mysql’ be the directory to which we want to relocate the database.

Steps to change the mysql database directory:

1. Execute the following command in the server to write the transactions saved in the memory to the hard disk.

mysqladmin -u root -p flush-tables

2.  Stop the mysql process in the server.

/etc/rc.d/init.d/mysql stop

3. Move the database files to the  the new directory.

 mv /var/lib/mysql/* /test/mysql/

4. Create symlink with the old directory.

 ln -s  /test/mysql /var/lib/mysql/

5. Give the correct ownership to the new directory.

chown -R mysql:mysql  /test/mysql/*

6. Restart mysql in the server.

/etc/rc.d/init.d/mysql start

Both comments and pings are currently closed.

Comments are closed.