Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm having the error 'can't connect to local MySQL server through socket 'var/lib/mysql/mysql.sock' (2)' when trying to log into mysqladmin and my sites have database connection errors.

Here's the tail of my /var/log/mysqld.log

120515 16:21:57  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 105040363025
120515 16:21:57  InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percents: 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 
InnoDB: Apply batch completed
120515 16:21:57  InnoDB: Waiting for the background threads to start

and my my.cnf file

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

skip-networking

# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0

# skip-bdb

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


query_cache_size = 1048576
query_cache_type=1
query_cache_limit=1048576

It looks like mysql.sock should exist in /var/lib/mysql/mysql.sock but it does not.

One solution I have tried from other threads is changing the permissions. This seemed to make a difference in that I got a 111 error (connection refused) but then it went back to a 2 error. Because I tried this it is possible that my ownerships and permissions are now not deal, so any recommendations might consider this.

The first solution I tried was to update mysql using the instructions here http://www.atomicorp.com/wiki/index.php/Mysql but I get stuck at

mysql_upgrade -u admin -p

with the below error

Enter password: 
Looking for 'mysql' as: mysql
Looking for 'mysqlcheck' as: mysqlcheck
Running 'mysqlcheck with default connection arguments
mysqlcheck: Error: Couldn't execute 'SHOW DATABASES': Lost connection to MySQL server during query
Running 'mysqlcheck with default connection arguments
mysqlcheck: Got error: 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111) when trying to connect
FATAL ERROR: Upgrade failed

Any recommendations?

Thank you.

share|improve this question
    
Chrooted webserver/php? If so the path is not located under chroot, use IP connection of modify my.cnf to use different location (example: chroot is /var/www - then my.cnf would be /var/www/var/lib/mysql/mysql.sock). –  Jiri Xichtkniha May 15 '12 at 19:29
    
Thanks. There actually isn't a my.cnf file. I tried making one but it didn't help. I'm really, really confused about this - I restored to a server image due to a completely unrelated file loss issue and I've now got all these MySQL errors I've never seen before & the host is being most unhelpful. –  user58639 May 16 '12 at 17:20
    
If you don't have a my.cnf then it is probably the socket file location that is wrong. Run ps aux|grep mysql and see check the path of the socket file then use '-s' with the client to connect using it. –  Sameer May 18 '12 at 12:10
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.