Change MySQL Data Directory Path

You can change the storage path of data in MySQL by modifying the configuration file. Here are the steps to change the data storage path in MySQL:

  1. Locate the configuration file for MySQL. In most cases, the configuration file for MySQL is named my.cnf and can be found in the MySQL installation directory.
  2. Open the my.cnf file and locate the datadir parameter, which specifies the storage path for MySQL data. By default, the datadir parameter is usually set to /var/lib/mysql.
  3. Change the value of the datadir parameter to the desired path for storing data. Make sure the specified path has enough space and the correct permissions.
  4. Save and close the my.cnf file.
  5. Restart the MySQL service to apply the changes. You can restart the MySQL service by entering the following command in the terminal.
sudo service mysql restart
  1. Ensure that your data has been successfully migrated to the new storage path. You can view the data storage path by executing the following SQL statement in MySQL:
SHOW VARIABLES LIKE 'datadir';

This completes the process of changing the MySQL data storage path. Be sure to back up important data before changing the data storage path to prevent data loss.

bannerAds