To change the MySQL database directory location on a CentOS ECS, you can follow these steps:
1.Stop the MySQL service: First, log in to your CentOS ECS as root and stop the MySQL service. You can use the following command to stop the MySQL service:
sudo systemctl stop mysqld
2.Create a new MySQL data directory: Suppose you want to change the MySQL data directory from var lib mysql to new mysql data, you need to create a new directory first and set the correct permissions:
sudo mkdir -p /new/mysql_data
sudo chown -r mysql:mysql /new/mysql_data
3.Copy an existing database to a new directory: Use the following command to copy an existing database file from the old directory to the new directory:
sudo cp -r /var/lib/mysql/* /new/mysql_data/
4.To modify the mysql configuration file, edit the mysql configuration file etc mycnf, find the datadir parameter and change its value to the new data directory path new mysql data.
5.Restart the MySQL service: After saving and closing the configuration file, restart the MySQL service for the changes to take effect:
sudo systemctl start mysqld
6.Verify the changes: Verify that the mysql database is working properly by logging in to the mysql database and executing some queries.
The above is the basic procedure to change the directory location of a MySQL database on a CentOS ECS. Please note that before making such changes, it is important to back up important database files in case something unexpected happens.