Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Many questions on this point but I couldn't any help yet. Mysql was working then I tried to move mysql database directory as (in this question)[] which I already successfully used several times but this time something went wrong and I got the error

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

so I reinstalled mysql (several times as I kept getting that error), mainly with the following commands:

# ** uninstall:
sudo su
rm -r /var/lib/mysql # delete the database
aptitude remove mysql-server mysql-client mysql-common
apt-get autoremove
apt-get autoclean

# ** reinstall
apt-get install mysql-server mysql-client mysql-common
apt-get update

The disk is not full and I think think the problem is that at some point somehow I managed to get /etc/apparmor.d/usr.sbin.mysqld deleted and now I have the previous problem and also

$ service mysql status
mysql: unrecognized service

The disk is not full and if I reinstall mysql the file is not added. So, thanks to @AbrahamVanHelpsing I got the file from source, but the problem stills. Any ideas?



aa-status did not mention mysql but it does now that I put the file that was missing.

Another edit

I can access mysql by running sudo mysqld and then mysql from another terminal, I still hope to register mysql in apparmor though

share|improve this question
What do you see when you run sudo aa-status? Is there any reference to mysql in the output? And, sudo apt-get apparmor-profiles may have something for mysql. – user25656 Jan 20 '13 at 5:35
@vasa1, thanks I updated my question – ecoologic Jan 20 '13 at 22:15

You need to add the new MySQL location to apparmor alias.

To add it, simply type

sudo nano /etc/apparmor.d/tunables/alias

And add this to the end of the file

/your/new/data/dir -> /var/lib/mysql

Note: you may see the ubuntu buit-in manual in the file

And type

sudo invoke-rc.d apparmor reload

Then it should work

Or a simpler solution

Remove AppAmor

sudo apt-get purge apparmor
share|improve this answer
I don't really think anyone wants to remove apparmor! I'll try that once at home, thanks by now! – ecoologic Jan 20 '13 at 22:14

Your Answer


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.