Self-Solve Knowledge Search

Minimize Maximize
Moving MySQL Data directory to different location
Title :
Moving MySQL Data directory to different location
Document ID :
KM00965731
Product - Version:
network automation 9.22 ;
OS :
Updated :
Fri May 30 19:39:12 GMT 2014
Summary :
Here you will find the steps you will need to follow when you need to move your MySQL data to a different location.
Here you will find the steps you will need to follow to change the directory of MySQL data to another partition or directory.
Solution
1.       Stop MySQL using the following command:
sudo /etc/init.d/mysql stop
 
2.       Copy the existing data directory (default located in /opt/mysql/data) using the following command:
sudo cp -R -p /opt/mysql/data/ /<newpath>/
 
Where <newpath> is the new location you need to move the data. In my example is tmp/MySQL-Test
 
Example: sudo cp -R -p /opt/mysql/data/ /tmp/MySQL-Test
 
3.       Edit the following MySQL configuration files:
  •  /opt/NA/server/conf/my.cnf
  • /etc/my.cnf
                There are two lines on each file. Taking the last example, both should look like this:
                datadir = /tmp/MySQL-Test/data
                innodb_data_home_dir = /tmp/MySQL-Test/data
 
4.       Restart MySQL services:
 
sudo /etc/init.d/mysql restart