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
First you should stop the mysql server. e.g.
After that you should copy the old data directory (e.g. /var/lib/mysql) incl. privileges to your new directory via
now you can change in
/etc/mysql/my.cnf
the data new and restart the serverUnder SuSE 13.1, this works fine to move the mysql data directory elsewhere, e.g. to /home/example_user/ , and to give it a more informative name:
In /var/lib/ :
I restarted mysql:
but suspect that even that wasn't necessary.
In case you're a Windows user and landed here to find out that all answers are for Linux Users, don't get disappointed! I won't let you waste time the way I did.
A little of bullshit talk before solution:
MySQL uses a Data directory to store the data of different databases you create. Well, in the end, it has to store them in the form of files with some added jugglery in the application and file format to ensure the Database promises that you learned in Databases classes are intact.
Now you want to make sure there is enough space to store large databases which you might create in future, and so you thought, Hey! I want to put it into another drive which has got more space.
So you do the following.
Step - 1 : Stopping MySQL service.
Step - 2 : Finding out the current Data directory
By default, there should be a folder here named
Data
, this is the one which is used by MySQL in default setting (provided they haven't found another better location), but let's check that out.Find
my.ini
file, should be right there.Open it in an editor (Notepad++ maybe).
Do a CTRL+F to find out
datadir
in the file.Whatever is mentioned here is the actual location currently under use by MySQL for data directory. This is what you want to change.
Step - 3 : Replacing it with a new data directory.
Let's say you want your new data directory to be W:__MySQL_Data. Let's change
datadir
value inmy.ini
file to this value. Keep the previous value commented so that you won't have to remember it.Now use
xcopy
to copy the defaultdatadir
toW:\
. Launch command prompt (Window + R, cmd, Enter)And rename the copied folder to the new
datadir
value that you changed. Here:W:/__MySQL_Data
Why not simply copy? Well because that's not COOL!, this helps you not lose permissions on the copied folder, so that when you restart
MySQL80
, it won't give a stupid error: "The MySQL80 service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs." - Courtesy:MicrosoftStep - 4 : Restarting the service
Step - 5 : Done! Now get back to work !!
you would have to copy the current data to the new directory and to change your
my.cnf
your MySQL.You have to copy the database when the server is not running.
I wanted to keep a database on my machine, but also have a data on my external hard drive, and switch between using the two.
If you are on a Mac, and installed MySQL using Homebrew, this should work for you. Otherwise, you will just need to substitute the appropriate locations for the MySQL
datadir
on your machine.Then to when you want to switch back simply do:
and you are using your local database again. Hope that helps.
First stop mysqld
Then change datadir in your
/etc/mysql/my.cnf
Start mysqld
Notes:
#1: probably you have to adjust your SELinux settings (try out with SELinux disabled in case of troubles), Apparmor (Ubuntu) may also be issue.
#2: see MySQL Install DB Reference