How to change a default MySQL directory /var/lib/mysql to another?

Created:

2016-11-16 12:54:51 UTC

Modified:

2017-05-04 10:06:15 UTC

1

Was this article helpful?


Have more questions?

Submit a request

How to change a default MySQL directory /var/lib/mysql to another?

Applicable to:

  • Plesk 12.5 for Linux
  • Plesk Onyx for Linux
  • Plesk 12.0 for Linux

Question

How to change a default MySQL directory /var/lib/mysql to another?

Answer

  1. Create a backup of /etc/my.cnf :

    # cp /etc/my.cnf{,_backup}
  2. Copy all files from /var/lib/mysql to a desired directory:

    # cp -r /var/lib/mysql /data/mysql
  3. Update /etc/my.cnf by changing the location to where you have copied mysql directory:

    # vi /etc/my.cnf
    datadir=/data/mysql
  4. Restart mysqld :

    # service mysqld restart
  5. Update /etc/psa/psa.conf with a path to the new mysql directory:

    MYSQL_VAR_D /data/mysql

Note: Be sure that the path to socket mysql.sock is unchanged in my.cnf and it is /var/lib/mysql . Also the directory /var/lib/mysql itself should present on the server as changing the path to the socket can cause Plesk crush.

Have more questions? Submit a request
Please sign in to leave a comment.