I had mysql server running. I stopped it, and removed it (apt-get remove mysql-server mysql-client)

I then manually removed the directories:


I rebooted. But when I type mysql, I get the following message:

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

I get the same error message when I type service mysql stop

This means mysql server is still running. How do I get rid of it completely and stop the process.

4 Answers 4


The error does not mean that you still have MYSQL server running. In fact, if the client can not connect to it, probably you don't have it running.

You still have the client available for execution: mysql

You can find out the package where mysql is, with:

dpkg -S `which mysql`

Then remove it, if you really want to do that.

  • You mean removing that directory? I did remove the client through apt-get remove mysql-client, this is why the message did not make sense to me Apr 10, 2014 at 23:34
  • The previous command returns the name of a package. Remove that package with sudo apt-get remove mysql-client-core-5.5
    – estibordo
    Apr 11, 2014 at 15:09

mysql-server and mysql-client are often virtual packages that depend on a more version-specific mysql package, like mysql-server-5.5 and mysql-client-5.5.

You can check for what MySQL packages are still installed using the following command:

dpkg --get-selections | grep -v deinstall | grep "^mysql"

Then you can use this list to apt-get remove whichever packages you want. You may also want to run an apt-get autoremove to get rid of unused packages when you're finished.


Would you check out your mysql really running?

Please try

ps auxw|grep mysql

I have some test like below, I could get same error when i shut down mysql server.

root@ubuntuz:~# ps auxw|grep mysql
mysql     1361  0.2  1.2 326532 11340 ?        Ssl  Feb19 162:34 /usr/sbin/mysq d
root     24553  0.0  0.0   5576   800 pts/0    S+   08:43   0:00 grep --color=auto mysql
root@ubuntuz:~# service mysql stop
mysql stop/waiting
root@ubuntuz:~# mysql -uroot -p mysql
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
root@ubuntuz:~# ps auxw|grep mysql
root     25009  0.0  0.0   5576   800 pts/0    S+   08:48   0:00 grep --color=auto mysql

Yes, it is still running. Just do this.

sudo apt-get remove --purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean

and after, if you try with

sudo mysql -u root -p

the terminal end-up as:

sudo: mysql: command not found

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.