
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
- Active Directory
- Cluster
- Database
- Exchange
- Files and folders
- Hardware
- Network
- Operating System
- PKI
- SCCM
- Service and process
- Tips
- VMWare
Change the MySQL datadir