How to change the storage path for MYSQL database files?
To change the storage path of the MySQL database file, you can follow the steps below:
- Stop the MySQL service.
- Locate the MySQL configuration file my.cnf (usually found in the bin folder within the MySQL installation directory for Windows systems and in the /etc/mysql or /etc directory for Linux systems).
- Open the my.cnf file and locate the [mysqld] section.
- Add or modify the following parameters in the [mysqld] section:
- datadir: specifies the location where MySQL data files are stored.
- innodb_data_home_dir: Specifies the directory where the data files for the InnoDB engine are stored.
- innodb_log_group_home_dir: specifies the location where InnoDB engine’s log files are stored.
- innodb_undo_directory: specifies the path where InnoDB engine’s undo log files are stored.
- For example,
- [mysqld]
Data will be stored in the new data path, while log and undo files will be stored in the new log and undo paths. - Note: The path must be an absolute path.
- Save and close the my.cnf file.
- Start the MySQL service.
After completing the above steps, the file storage path for the MySQL database will be changed to the specified path.