Change default MySQL Data Directory in Linux

Rate this post

Mostly MySQL uses /var/lib/mysql directory as default data directory for Linux based systems

We are showing here how to change the default directory to different directory.

Follow the below steps to make all the changes. In some cases service name, default data directory or MySQL configuration file path change. So use all the command as per you system settings.

1. Stop MySQL

Before making any changes, first make sure to stop mysql service

# service mysqld stop

2. Change Data Directory

Now copy default mysql data directory (/var/lib/mysql) to other location as per your requirement. Also set the required mysql ownership on new directory location.

# cp -rap /var/lib/mysql /data/mysql
# chown mysql.mysql /data/mysql

Now edit MySQL default configuration file /etc/my.cnf and update values of datadir and socket variable.

Change From:

Change To:

3. Start MySQL

After making all above changes. finally start MySQL service. Now it will use new data directory path

# service mysqld start

This article has been tested with CentOS 6.5 with MySQL 5.5.37. If you face any issue during MySQL startup check mysql log file /var/log/mysqld.log for any errors.



Related Posts

  • 45
    cd : Change Directory The cd command, which stands for "change directory", changes the shell's current working directory. It is a builtin command, which means that it is executed directly by your shell, instead of launching an external program. cd is a command-line OS shell commandused to change the current working directory…
    Tags: directory, change, linux, changes
  • 38
    I tried the following steps: Log in as super user or use sudo Open /etc/mysql/my.cnf using gedit Check the all the configuration Find bind-address, and change its value to the database server host machine's IP address. For me, it was localhost or Save and close the file. Come back…
    Tags: mysql, change, file, start, service
  • 35
    rsync = Remote Sync This is a remote and local file synchronization tool. It uses an algorithm that minimizes the amount of data copied by only moving the portions of files that have changed. This is a very flexible network-enabled syncing tool. Due to its ubiquity on Linux and Unix-like…
    Tags: data, directory, file, linux
  • 34
    change to asterisk source directory and do it: make config chkconfig asterisk on after that you can reboot.  
    Tags: start, directory, change, service

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: