MySQL is a commonly used relational database management system that stores data files in a specific directory by default. However, sometimes we want to change the default data directory to a path we want. The following are detailed steps to modify the MySQL default data directory.
Step 1: Stop the MySQL service
Before modifying the data directory, we need to stop the running MySQL service. You can use the following command to stop the MySQL service:
sudo service mysql stop
Step 2: Copy the data directory
Before making modifications, we should back up the previous data directory to the new directory. You can use the following command to perform a copy operation:
sudo cp -R /var/lib/mysql /new/datadir/path
Please /new/datadir/path
replace with the path to the new data directory you want to set up.
Step 3: Modify MySQL configuration file
Next, we need to modify the MySQL configuration file to specify the new data directory.
Use a text editor to open the MySQL configuration file my.cnf
. On most Linux distributions, this file is located under the /etc/mysql/my.cnf
or /etc/my.cnf
path. Find the following line:
datadir <