7/24/2023 0 Comments Mysql database file location linuxSteps to Change Default data Directory in MySQLįollow the below steps to make all the changes. In this tutorial, we will help you to change the default data directory for MySQL and move it to some other location. This is fine for the development systems but we don’t recommend keeping/var/lib/mysql on the root file system for production servers. Most of the operating systems have mounted /var directory on root (/) file system. On the Linux system, MySQL stores all the files under /var/lib/mysql directory. You can find the installation instructions here. MySQL is available for all the major operating systems like Windows, Linux, and macOS. It is widely used by web applications for storing data permanently. In this post, we have discussed how to change the data directory in a MySQL or MariaDB server running on CentOS/RHEL 7 and Ubuntu/Debian distributions.MySQL is a popular relational database management system (RDMS). Login to MariaDB, create a new database and then check /mnt/mysql-data: # mysql -u root -p -e "CREATE DATABASE tecmint "Ĭongratulations! You have successfully changed the data directory for MySQL or MariaDB. Now, use the same command as in Step 1 to verify the location of the new data directory: # mysql -u root -p -e "SELECT MySQL New Data Directory Step 5: Create MySQL Database to Confirm Data Directory # semanage fcontext -a -t mysqld_db_t "/mnt/mysql-data(/.*)?" This step is only applicable to RHEL/CentOS and its derivatives.Īdd the SELinux security context to /mnt/mysql-data before restarting MariaDB. Configure New MySQL Data Directory Step 4: Set SELinux Security Context to Data Directory Save the changes and then proceed with the next step. Locate the and sections and make the following changes: Under : Then copy recursively the contents of /var/lib/mysql to /mnt/mysql-data preserving original permissions and timestamps: # cp -R -p /var/lib/mysql/* /mnt/mysql-dataĬopy MySQL Data Directory to New Location Step 3: Configure a New MySQL Data DirectoryĮdit the configuration file ( my.cnf) to indicate the new data directory ( /mnt/mysql-data in this case). If the service has been brought down, the output of the last command should be as follows: Stop MySQL Service Use the systemd well-known commands to do so: - On SystemD. To avoid data corruption, stop the service if it is currently running before proceeding. Identify MySQL Data Directory Step 2: Copy MySQL Data Directory to a New Location # mysql -u root -p -e "SELECT you enter the MySQL password, the output should be similar to. Do not just assume it is still /var/lib/mysql since it could have been changed in the past. To begin, it is worthy and well to identify the current data directory using the following command. # mkdir /mnt/mysql-dataįor your convenience, we’ve divided the process into 5 easy-to-follow steps: Step 1: Identify Current MySQL Data Directory It is important to note that this directory should be owned by mysql:mysql. Note: We are going to assume that our new data directory is /mnt/mysql-data. Changing the default MySQL/MariaDB Data Directory Although we will use MariaDB, the concepts explained and the steps taken in this article apply both to MySQL and to MariaDB unless noted otherwise.
0 Comments
Leave a Reply. |