Ubuntu – MySQL won’t start!

MySQLUbuntu

I'm getting this error when trying to log into MySQL from the command line:

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

I think this means that MySQL hasn't been started yet. So I try to start it:

sudo /etc/init.d/mysql start

and I get this message:

* Starting MySQL database server mysqld [fail] 

Where do I look/what do I do to get MySQL to start? I am running Ubuntu 8.04 and installed MySQL through apt-get. I have been able to get it started and used it a couple times so I don't know why it just stopped working.

Update: When running sudo /etc/init.d/mysql status I get the message:

* MySQL is stopped.

Update #2: My log files (/var/log/mysql.log & /var/log/mysql.err) are empty (if these are the right ones)

Best Answer

On Ubuntu 12.04 I had this same problem after changing buffer sizes in /etc/mysql/my.cnf file, I think I got a little carried away. Anyway after trying to change them back to the default setting MySQL still would not start.

I tried several different methods to get it resolved, I did notice that /var/run/mysql/mysql.sock was missing. This could be an issue so you may check there and if its missing you can replace it by doing the following:

sudo touch /var/run/mysql/mysql.sock
sudo chown mysql /var/run/mysql/mysql.sock

This did NOT fix the problem for me! But it may for some.

What I had to do was completely reinstall MySQL, to do this you will need to use the sudo command. The steps to completely removing and reinstalling MySQL are as follows:

Remove MySQL

sudo apt-get --purge remove mysql-server
sudo apt-get --purge remove mysql-client
sudo apt-get --purge remove mysql-common

Optionally you may use aptitude, by replacing apt-get --purge with aptitude

Clean UP

sudo apt-get autoremove
sudo apt-get autoclean

Remove MySQL dir

sudo rm -rf /etc/mysql

Install MySQL

sudo apt-get install mysql-server mysql-client

MySQL should now be running, you can check this by doing the following:

sudo service mysql status

You should see

mysql start/running, process xxxxx

Hope this helps, and thought I might add after doing this all my databases and tables where still available, however I did have to recreate the users and passwords for those databases.

Note: If you had mysql extension for php, you will need to reinstall this too.

sudo apt-get install php5-mysql
Related Question