Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Here are the following commands I have done.

$ sudo service mysql start
mysql start/running

$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

$ aptitude search mysql |grep ^i
i   libapache2-mod-auth-mysql       - Module Apache 2 pour l'authentification vi
i   libdbd-mysql-perl               - Perl5 database interface to the MySQL data
i   libmysqlclient16                - MySQL database client library             
i   mysql-client-5.1                - MySQL database client binaries            
i   mysql-client-core-5.1           - MySQL database core client binaries       
i   mysql-common                    - MySQL database common files, e.g. /etc/mys
i   mysql-server-5.1                - MySQL database server binaries and system 
i   mysql-server-core-5.1           - MySQL database server binaries            
i   php5-mysql                      - MySQL module for php5                     
share|improve this question
    
alm - find your mysql.log cat /var/log/mysql.log and edit your answer withthis file.... –  hhlp Oct 19 '11 at 19:47
3  
I like the way you used grep ^i there. Pretty intelligent. –  Luis Alvarado Oct 19 '11 at 20:25
    
What exactly does it do? aptitude is installation tools. –  Jim Thio Aug 7 '12 at 9:13
    
@JimThio That's to find the installed packages related to this question. –  hexafraction Aug 14 '12 at 14:04

2 Answers 2

ERROR 2002 (HY000): Can not connect to local MySQL server-through socket '/ tmp / mysql.sock' (2)

In MySQL installations can specify where we will have the socket for local connections. When making updates is not uncommon to see the error "Can not connect to local MySQL server socket-through." Let's see how to solve this problem.

The error look like this:

Mysql-u root-p
Enter password:
ERROR 2002 (HY000): Can not connect to local MySQL server-through socket '/ tmp / mysql.sock' (2)

thru ps we can see if is specified by parameter and the place where is it:

# ps -fea | grep mysqld
mysql    17661 14003  1 Feb19 ?        00:24:59 /usr/local/mysql-percona/libexec/mysqld --basedir=/usr/local/mysql-percona --datadir=/var/data/mysql/datadir/data --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --socket=/var/lib/mysql/mysql.sock --log-error=/var/log/mysqld.log
root     23790  7840  0 09:25 pts/0    00:00:00 grep mysqld

In this case we see is in /var/lib/mysql/mysql.sock. If not found as a parameter should look into mysqld section of /etc/my.cnf to find the parameter:

grep socket /etc/my.cnf
socket=/var/lib/mysql/mysql.sock

If we know where is it we need to modify the same file (/etc/my.cnf) and add the parameter section socket client:

[client]
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
share|improve this answer
1  
That is what I was going to put as an answer. I already know this is the correct answer for almost all related problems like this. Will +1 you when I get the ability again. –  Luis Alvarado Oct 19 '11 at 20:24
    
thanks for the thorough explanation! in my case even if i specified a socket in my.cnf it didn't listen on it (params shown in 'ps' are empty and no connection possible. workaround: add 'protocoll=tcp' to client section in my.cnf to force using tcp and not the socket. –  Tapper Mar 31 '12 at 19:52

Before reinstalling check /var/log/mysql for logs files which may contain clues as to why mysql is not working. If there are no logs log to file might not be enabled in your configuration: Configure Mysql Error Log

To reinstall any package use

sudo apt-get install mysql-server-5.1 --reinstall

If this doesn't allow you to reconfigure the package you can use

sudo dpkg-reconfigure mysql-server-5.1
share|improve this answer
    
sudo dpkg-reconfigure mysql-server-5.1 did the trick for me when I upgraded from 11.10 to 12.04 i mysqld wouldn't start and i was forced to manually sudo mysqld –  Hanynowsky Mar 14 '12 at 2:12

Your Answer

 
discard

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.