Change the MySQL datadir
Change the MySQL datadir

Simple but useful, you will find below the steps on how to change the MySQL datadir. It is based on the following information (you have to adapt them according to your environment) :

  • current datadir : /var/lib/mysql
  • new datadir : /new_folder/mysql
  • MySQL configuration file : /etc/mysql/my.cnf

Procedure

  • Stop MySQL service : service mysql stop
  • Copy the datadir content (recursive) : cp -R /var/lib/mysql /new_folder/
  • Edit the MySQL configuration file and update the following line :
    • Before : datadir = /var/lib/mysql
    • After : datadir = /new_folder/mysql
  • Change the security information on the destination folder : chown -R mysql:mysql /new_folder/mysql
  • Start MySQL Service : service mysql start

After you validate everything is ok, you can remove the folder /var/lib/mysql

That’s all !

<>

My Powershell script categories

Change the MySQL datadir

Leave a Reply

Your email address will not be published.