8

I install mysql and try start

/usr/local/mysql/bin# ./mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
/usr/local/mysql/bin#

Any Idea?

Jorge Castro
  • 71,754
Miki
  • 261

4 Answers4

10

mysql can be started from upstart. Basically you install mysql-server package. You can easily search for mysql-server package in synaptic and install it. You will be prompted for root password during installtion[i.e.mysql user root password] . After that in terminal just do

sudo start mysql

or

sudo service mysql start

Mysql usually is started on boot so you may have it running as well.

Just ps aux | grep mysql to see if it is running.

sagarchalise
  • 23,988
6

Ubuntu 11.10: sudo dpkg-reconfigure mysql-server-5.1

Ubuntu 12.04: sudo dpkg-reconfigure mysql-server-5.5

Follow instruction then reboot.

This problem may happen when you upgrade from one ubuntu version to another and config gets messed up somehow. Usually the related to the startup process of mysql daemon mysqld)

Hanynowsky
  • 2,781
5

I see you are using /tmp/ for the mysql.socket so either you are not installing the mysql 5.1 that comes from ubuntu by default or you are installing mysql 5.5.x (which you need to mention in your question if this is the case). Anyway some of the things you can do are:

  1. Verify that mysql is not already running: ps -e|grep -i 'mysqld' if it appears then kill it. sudo killall -9 mysqld . If it does not die grab the pid from the ps you made here and kill -9 PID

  2. "Try" to run mysql via /etc/init.d/mysql start if it gives you the exact same error from above then you need to copy the mysql.server file from the mysql you downloaded which can be found in the support-files folder inside the mysql folder you downloaded or in the /usr/local/mysql folder and copy it to /etc/init.d/mysql (Example: cp mysql.server /etc/init.d/mysql and give it a executable permission chmod +x /etc/init.d/mysql then run it again.

  3. If it still gives you a problem then edit the config file in /etc/my.cnf (if you have 5.5 installed) or /etc/mysql/mysql.conf (if you have 5.1 installed) and change ALL the /tmp/mysql.socket lines to /var/run/mysqld/mysqld.sock. Note that the config file can also be in /etc/mysql/my.cnf.

    Test this but please ADD what mysql you are using, either 5.1 or 5.5. I mention 5.5 here because 5.5 is the one that uses /tmp and 5.1 uses the default /var/run

If by any change you happen to be using 5.5 then remember to delete the directories of old 5.1 from /etc/mysql, /var/lib/mysql and /user/lib/mysql

Luis Alvarado
  • 211,503
2

Change the server name from "localhost" to "127.0.0.1" in your connection params, Im sure it will do the trick.