Changing the default data directory in Mysql

Had to reconfigure the mysql data directory today. Found this stackoverflow link to be spot on.
stackoverflow-change mysql default data directory ( I really don’t want to be accused of plagiarism)
Reproducing the content here [Just in case the link disappears]

1. Stop MySQL using the following command:

sudo /etc/init.d/mysql stop

2. Copy the existing data directory (default located in /var/lib/mysql) using the following command:

sudo cp -R -p /var/lib/mysql /newpath

3. Edit the MySQL configuration file with the following command:

gedit /etc/mysql/my.cnf

4. Look for the entry for datadir, and change the path (which should be /var/lib/mysql) to the new data directory.

5. In the terminal, enter the command:

sudo gedit /etc/apparmor.d/usr.sbin.mysqld

6. Look for lines beginning with /var/lib/mysql. Change /var/lib/mysql in the lines with the new path. Save and close the file.

7. Restart the AppArmor profiles with the command:

sudo /etc/init.d/apparmor reload

8. Restart MySQL with the command:

sudo /etc/init.d/mysql restart

9. Now login to MySQL, and you can access the same databases you had before.

Cheers !!
The Nonsense Logger !!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s