Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

So I started running out of space on my linux hard disk. I added another hard drive and now I want to change the MySQL directories. So instead of saving the data into the old hard drive, it saves it into the new hard drive. The new hard drive is mounted as /Data/

I looked several ways to do it, and I followed each and every instruction. But every time I followed the instructions I get an error "ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'"

I tried moving the directory and then linking the old directory to the new one. Same error.

I tried moving the whole directory and changing the my.cnf file under etc to point at the new directory, I even changed the line socket=/Data/mysql/mysql.sock still the same error.

**Also, I did make sure all the ownerships were mysql:mysql

It fails to start each time. So I end up moving everything back to where it was and it starts successfully. I would really appreciate some help here.


share|improve this question
can you show us your mysql logfile? – Pascal Schmiel Apr 30 '13 at 14:13
Is the new directory mysql:mysql ? – NickW Apr 30 '13 at 14:16
This is just to check, did your mysql server instance crashed the last time when it ran out of disk space? If so, then your old mysql.sock file still exists. Make sure the old mysql.sock file is deleted before you start mysql server. – Nikolas Sakic Apr 30 '13 at 14:19
Thanks for the reply guys. No my server didn't crash. Like I mentioned, I can start it successfully if I leave everything as default. But as soon as I try to move the directory it won't start. – Zors Apr 30 '13 at 14:48

4 Answers 4

Once you move everything to the new folder you need to make sure that the folder has permissions and ownership mysql:mysql.

share|improve this answer
Thanks for the reply. I did check all the ownerships and made sure all of them are mysql:mysql – Zors Apr 30 '13 at 14:43
Is there anything else in /var/log/mysql/mysql.log or error.log? – Danila Ladner Apr 30 '13 at 14:47
What OS it is installed on? – Danila Ladner Apr 30 '13 at 14:56
The Operating System is CentOS – Zors Apr 30 '13 at 15:01

In the my.cnf you need to add the socket path in two places: In the [mysql] and in the ->[client]<- section.

Here is a typical global option file:



share|improve this answer
Ok done. Thanks. – GT00 Jan 15 at 12:40

The error you are getting is not one you get from starting mysql with things in the wrong place, but from the fact that you need to modify the socket location in the [client], `[mysqld] and any other location it shows up in, under my.cnf

share|improve this answer
I changed the socket file to the new destination under [mysqld] however [client] doesn't exist in my my.cnf file. Should I just add [client]? – Zors Apr 30 '13 at 14:51
There may be another location where it is configured, but even the client has to know where to connect to by default (if you don't put -h ). – NickW Apr 30 '13 at 14:54
I just tried to add [client] to the file and it still failed to start. [root@localhost etc]# service mysqld start mysMySQL Daemon failed to start. Starting mysqld: [FAILED] [root@localhost etc]# mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Data/mysql/mysql.sock' (2) – Zors Apr 30 '13 at 14:54
in your my.cnf do you have option: basedir=/var/lib? – Danila Ladner Apr 30 '13 at 15:05
No [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/ – Zors Apr 30 '13 at 15:07

It has nothing to do with sockets or permissions, I verified that selinux and apparmor were disabled and still mysql would not start.

I also tried symbolic links to /var/lib/mysql. Removing mysql and starting from scratch is the only way I could make it work.

step 1

completely remove mysql from your system

step 2

mount an external hard drive to /var/lib/mysql

step 3

install the latest version of mysql it will say there may be earlier versions in /var/lib/mysql, just ignore it.

Mysql can't tell the difference anymore, and all is well.

share|improve this answer
why the down vote, it's an unsolvable problem, the only way around it is to get rid of mysql and start from scrach, it's not my fault that mysql is designed badly. – user3338098 Nov 5 at 15:18
it wasn't me that downvoted you, but I think it's because your solution it's too unnecessarily extreme. I don't see why remove/install mysql again if it's only a matter of "mount + permissions". – Daniel Loureiro Nov 10 at 12:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.