Is it possible to change my default MySQL data directory to another path? Will I be able to access the databases from the old location?
相关问题
- sqlyog export query result as csv
- How to access the camera from my Windows Phone 8 a
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
- Why sometimes there is one of more gap(s) in the v
We had to move MySQL into
/home
directory because it was mapped from another physical disc. In order to make live simpler, instead of changing directory in my.cnf, we have mapped the new directory/home/mysql
in the place of the original directory/var/lib/mysql
. It works for us like a charm (tested on CentOS 7.1).Create the new dir and set correct permissions.
Stop MySQL if running.
Move the data dir.
Create a permanent mount and execute it.
Restart the server.
Quick and easy to do:
Edit the
/etc/my.cnf
file, and under[mysqld]
add this line:If you are using CageFS (with or without CloudLinux) and want to change the MySQL directory, you MUST add the new directory to this file:
And then run this command:
If you are using SE linux, set it to permissive mode by editing /etc/selinux/config and changing SELINUX=enforcing to SELINUX=permissive
Stop MySQL using the following command:
Copy the existing data directory (default located in
/var/lib/mysql
) using the following command:edit the MySQL configuration file with the following command:
Look for the entry for
datadir
, and change the path (which should be/var/lib/mysql
) to the new data directory.In the terminal, enter the command:
Look for lines beginning with
/var/lib/mysql
. Change/var/lib/mysql
in the lines with the new path.Save and close the file.
Restart the AppArmor profiles with the command:
Restart MySQL with the command:
Now login to MySQL and you can access the same databases you had before.
If you want to do this programmatically (no manual text entry with gedit) here's a version for a Dockerfile based on user1341296's answer above:
Available on Docker hub here: https://hub.docker.com/r/richardjecooke/ruby-mysql-in-memory/
First stop your mysql
copy mysql data to the new location.
if you use apparmor, edit the following file and do the following
Replace where /var/lib/ by /yourdirectory/ then add the follwoing if no exist to the file
Save the file with the command
Edit the file my.cnf
Replace where /var/lib/ by /yourdirectory/ then save with the command
finally start mysql
@see more about raid0, optimization ici