Moving mysql var/lib/mysql to /home/mysql

Awd

Verified User
Joined
Aug 9, 2015
Messages
316
Hi,

I need to move mysql from var/lib/mysql to home/mysql.
I found this help to do:
https://help.directadmin.com/item.php?id=12
Code:
cd /home
mkdir mysql
chown mysql:mysql mysql
cd mysql

perl -pi -e 's/mysqld=ON/mysqld=OFF/' /usr/local/directadmin/data/admin/services.status
/sbin/service mysqld stop

cp -Rp /var/lib/mysql/* .
cd /var/lib
mv mysql mysql_old
ln -s /home/mysql ./mysql

/sbin/service mysqld start
perl -pi -e 's/mysqld=OFF/mysqld=ON/' /usr/local/directadmin/data/admin/services.status

#once satisfied that mysqld is running and functioning correctly, remove the old data:

rm -rf mysql_old

My question, is there any difference when installed Mysql with Mariadb?

And finally, let´s assume something gone wrong, how to revert it quickly?
 
[FONT=&quot][/FONT]Hello,[FONT=&quot]

MariaDB was created in 2009 by the same people behind MySQL, one of the most popular Open Source relational databases. The founders were inspired to develop MariaDB as an alternative to MySQL, after Oracle acquired MySQL through the Sun Microsystems acquisition. MariaDB has since replaced MySQL in many mission-critical applications and is quickly replacing other legacy relational databases in a wide variety of applications.

[/FONT]
You can treat MariaDB the same way as MySQL.

[FONT=&quot][/FONT]In order to revert it back you should undo every step.
 
In order to revert it back you should undo every step.

Like this or......do I oversee something
Code:
cp -Rp /var/lib/mysql/* .
cd /var/lib
mv old mysql_mysql
ln -s /var/lib/mysql ./mysql

assuming I do not have deleted the mysql_old directory yet. It is just meant as quick fallback in case something go wrong.
 
Last edited:
I did not test the steps you provided on a Linux box in your second post. So I don't guarantee anything unless I do it myself. So be careful.

Anyway this command cp -Rp /var/lib/mysql/* . won't do what you want when you are already in /var/lib/mysql/. And the whole block

Code:
cp -Rp /var/lib/mysql/* .
cd /var/lib
mv old mysql_mysql
ln -s /var/lib/mysql ./mysql

is looking rather messy. Undoing a step does not always mean that you change parameters of a command. And if you created a symlink the only way to undo it is to remove it, and not to create a symlink with another name. If you removed a folder you should re-create it if you want to undo it, you should not remove a folder with different name.

Please note and understand
, these forums would expect that you have an experience working in a bash-console, as we don't teach what commands to use in order to create/delete folders, symlinks.So the only really valuable help will be to suggest that you read the original steps line by line and understand what you do. If you want to work in Linux console you need to understand at least basic commands.

The idea of the original move is to:

1. create a new folder at a partition where you expect to have more disk space.
2. copy/move data from original folder to a new folder
3. delete old folder
4. create a symlink

and in order to revert it back you should start from step #4 and undo every step while you are moving from step #4 to #1.
 
Okay thanks and allthough I am not an Linux expert, the creation of a symlink is what confusing me.

I know how to do without creating a symlink, I copy the folder with rsync to home/mysql and then edit my.cnf and add
[mysqld]
datadir=/home/mysql
socket=/home/mysql/server.sock

But I am not sure if an future update will override these custom settings and that is why I asked about the symlink way.
 
I would rather not change the socket location, as a need to update settings for PHP, Directadmin in this case might appear. That's why a symlink is used.
 
should be ok to set datadir and socket

I would rather not change the socket location, as a need to update settings for PHP, Directadmin in this case might appear. That's why a symlink is used.

...just to note, referenced at the bottom of the resource OP linked to is:

https://www.directadmin.com/features.php?id=140

As we work for more flexibility with other operating systems, we need to be able to change the mysql socket on the fly (per install). By adding:

Code:
socket=/path/to/mysql.sock

to the /usr/local/directadmin/conf/mysql.conf file, it will use this socket instead of the defaults ( /var/lib/mysql/mysql.sock for redhat and /tmp/mysql.sock for freebsd)
 
I don't recall any single issue with changing socket location on CentOS, but had various issues with a socket location in Debian and Ubuntu. So still I would not recommend doing it to anybody without enough experience.
 
Back
Top