# SOLVED: Can't connect to local MySQL server through socket

## jtmace

Last night I copied my my system to a 300GB SATA hd.  Everything seems to work well.. I used the LiveCD to perform the actual transfer so no filesystesm was mounted elsewhere. 

I had 2 services not come up. ATD and MYSQL.    I fixed the ATD by just changing the permissions of its /var/run dir.  

MySQL is borked, and I've had no luck at all finding the solution..  Gentoo's mysql rc script appears to start and stop correctly.   Anyone know whats going on?   Did the cp -R not copy file ownership and permissions?  Everything else works fine..

--------------------------------------------------------------------------

When I try to run mysql

```
mysql # mysql

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)

```

I changed the permissions to ugo+rwx just to ensure it was readable

```
mysql # ls -la /var/run/mysqld

total 8

drwxr-xr-x  2 mysql mysql 4096 Jul 16 17:56 .

drwxr-xr-x  5 root  root  4096 Jul 16 17:56 ..

-rw-r--r--  1 mysql mysql    0 Jul 16 13:21 .keep

srwxrwxrwx  1 mysql mysql    0 Jul 16 17:56 mysqld.sock

```

Relevant section of My.cnf

```

[client]

port                                            = 3306

socket                                          = /var/run/mysqld/mysqld.sock

```

I've changed the owner to apache, but that didnt fix either..  

I even re-emerged mysql, but the error is still present.Last edited by jtmace on Mon Jul 17, 2006 4:57 am; edited 1 time in total

----------

## smiffy

You've probably already checked this, but anyhow...

*Have you looked at the process table to see if MySQL is actually running, and that it is running as user mysql?

*Have you checked the log files in /var/log/mysql to see if MySQL is complaining about anything?

*Try connecting through the port rather than the socket (I've had problems in the past where I could hit the port but not the socket): 

```
mysql --port=3306 --host=localhost
```

----------

## jmbsvicetto

Moved from Installing Gentoo to Networking & Security.

[mod]Since this is not an install question and relates to MySQL, I believe it belongs in N&S.[/mod]

jtmace,

to copy your system, you should use cp -a as cp -R won't preserve permissions.

Look at the permissions in /var, /var/run and /tmp.

----------

## jtmace

I didnt know if copying a system to a different disk was technically an "install"  :Very Happy: 

The mysql process is not running. Gentoo is happy to report that it brings it up and down, but a ps indicates no mysqld processes.  

All the ownerships and permissions appear to somewhat be intact.  Tmp was not UGO+RWX on the copied versions, but on the original disk they are.  Other than that not much else has changed. 

I'm emerging mysql 5 now, hopefully kill 2 birds (prob fixed + upgrade).

----------

## jtmace

emerging version 5 didnt fix the problem, but it did provide a message in /var/log/mysql/mysqld.err that helped me solve it. I did not know of this /var/lib/mysql dir..   That answered many questions I had yet to ask. 

I `chown mysql:mysql /var/lib/mysql` and now everything is happy. 

/var/lib/mysql turns out to contain the filesystem storage of the databases.  I thought for sure after my original unmerge of mysql this morning that I had lost all of my databases, and I have no back-up (no big deal, but still alot of work), but much to my surprise all of them were there, unaffected.

----------

## smiffy

No backup?

```
man mysqldump
```

 :Wink: 

----------

## jtmace

It was a fresh install..  Its easy enough to export the tables but I havent had time to set it all up..  All the data was very much expendable.

I decided to scrap the current contents of sda1 (my root partition) and reload with a 'cp -a' instead of a cp -R.  Everything works like a champ now.

I had got mysql working again, but learned the permission probem's extent was much greater than I originally expected..  oh and MythTV was broken too, I chased down some stuff granted privs for the mythtv user again, but no luck..  I didnt feel like chasing all the problems for 4 different users (mysql apache snort mythtv - cause all of them were broken)..

----------

