I could successfully alter the data directory of MySQL or MariaDB, and resolve all related issues on Fedora 30. I think the following steps will work on other distributions. Show
Note: Users of Disabling SELinuxFirst of all, let me mention that RedHat-based Linux
Distributions (RHELs) like Fedora, CentOS, etc. use SELinux that enforces mandatory access control policies. So it's better to Open the SELinux configuration file
Locate the line that contains Changing the datadir of MySQLStop the MySQL services
Make a new directory for MySQl's data directory. Due to some reasons which are out of the scope of this solution, it's highly recommended to not create a data directory under the
Set ownership and permissions of the new directory to the default MySQL's data directory(
Copy all files from the default directory to the new one
Edit the
Now you can start your MySQL service via the following command
But if the data directory is created under
Resolving /home issuesMake sure that all the parent directories of the new
As it is mentioned creating datadir under
copy the following lines to the new
Apply the changes by running the following command
Now you can run the MySQL service:
Enabling SELinuxAgain edit the To query the current status of SELinux use the following commands, it should print
the
Now you can run MySQL. Cheers ;-) After installing MySQL database for a production server, we may want to change the default data directory of MySQL to a different directory. This is the case when such directory is expected to grow due to high usage. Otherwise, the filesystem where In order to change the default directory, we need to check the available storage. We can use the We are going to assume that our new data directory is mkdir -p /home/mysql-data For simplicity, I’ve divided the procedure into 4 simple steps. Step 1: Identify Current MySQL Data DirectoryTo identify the current data directory use the following command. mysql -u username -p -e “SELECT @@datadir” We need to identify the current MySQL data directory as it can be changed in the past. Let’s assume the current data directory is Step 2: Copy MySQL Data Directory to the desired locationTo avoid data corruption, stop the service if it is currently running before proceeding and check the status. service mysqld stop Then copy recursively the contents of cp -rap /var/lib/mysql/* /mnt/mysql-data Change the permission of the directory as its owner should be chown -R mysql:mysql /mnt/mysql-data Step 3: Configure the new MySQL Data DirectoryEdit the MySQL default configuration file /etc/my.cnf and update values of mysqld and client. # Change From:[mysqld] If there is no client variable then add, or else, update it to: [client] Step 4: Enable the MySQL Service and confirm the directory change Restart the MySQL service using the following command: service mysqld start Now, use the same command to verify the location change of the new data directory: mysql -u username -p -e “SELECT @@datadir” If you face any issue during MySQL startup check MySQL log file That’s it. Hope this helps. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend or sharing it on Twitter or Facebook. Thank you! What is the MySQL data directory?The mysql directory corresponds to the mysql system schema, which contains information required by the MySQL server as it runs. This database contains data dictionary tables and system tables.
How do I find MySQL data directory?Resolution. Open up MySQL's configuration file: less /etc/my.cnf.. Search for the term "datadir": /datadir.. If it exists, it will highlight a line that reads: datadir = [path]. You can also manually look for that line. ... . If that line does not exist, then MySQL will default to: /var/lib/mysql.. How do I initialize a MySQL data directory?Connect to the server:. If you used --initialize but not --initialize-insecure to initialize the data directory, connect to the server as root : mysql -u root -p. ... . If you used --initialize-insecure to initialize the data directory, connect to the server as root without a password: mysql -u root --skip-password.. What is data directory in database?The data directory provides an overview of the data managed by each service unit including the master data managed by the service unit, and the data that is replicated from the master data of another service unit. It references the (ELDM, discussed below) to identify the business data entities.
|