Change MySQL Data Directory in Linux
This post discussing how to change MySQL Data Directory. As everyone knows the default MySQL data directory is /var/lib/mysql. You can change it using the following steps.
1. Find out where the databases are
By default, the databases (as a file) are stored in “/var/lib/mysql/” on Linux. Verify the current data directory location using any one of the following commands.
mysqladmin var -u root -p | grep datadir
root@server [~]# mysqladmin var -u root -p | grep datadir Enter password: | datadir | /var/lib/mysql/
OR login to interactive MySQL session with the below command:
mysql -u root -p
Once logged in, run the following command on MySQL interactive session.
mysql> select @@datadir; +-----------------+ | @@datadir | +-----------------+ | /var/lib/mysql/ | +-----------------+ 1 row in set (0.00 sec) mysql>
2. Stop MySQL Service
I am planning to move MySQL Data Directory to /home/mysql. Before making the changes, you need to make sure that the MySQL service is stopped.
service mysqld stop
3. Change MySQL Data Directory
Now move MySQL data directory to the desired location and make sure that the directory ownership is set to mysql.
cp -pr /var/lib/mysql /home/mysql chown -R mysql.mysql /home/mysql
4. Edit MySQL Configuration
Once done, edit MySQL configuration file /etc/my.cnf using your favourite editor. I am using VIM here.
and update the following variables.
5. Start MySQL Service
service mysqld start
In this way, you can change MySQL data directory in Linux. Please check the MySQL error log if you encountered any problems.
- How To upgrade MySQL in InterWorx Server
- How to disable MySQL strict mode on cPanel
- Recover mysql root password
- How to disable automatic updates in WordPress
- How to increase tmp directory size in cPanel
- How to change IP of all domains in Plesk
- Clear eximstats DB in cPanel
- How to install phpMyAdmin in an account on cPanel
- Fix: WARNING: A running easyapache process was detected
If you like this post and wish to receive more articles from us, please like our FB page: GrepItOut
Your suggestions and feedbacks will encourage us and help to improve further, please feel free to write your comments.
For more details on our services, please drop us an E-mail at firstname.lastname@example.org