If your mysql seems broken and giving errors like:
# service mysql start start: Job failed to start
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Or if you try to recreate databases with mysqlinstalldb:
... ... ERROR: 1 Can't create/write to file './mysql/db.frm' (Errcode: 13) 041226 xx:xx:xx /usr/libexec/mysqld: Can't find file: './mysql/db.frm' (errno: 13)
or all your databases go missing, even if you reinstall mysql-server.
and reinstalling mysql-server won’t work,
Before you reformat the server and use your data, you should try doing (as root, or using sudo):
apt-get install --reinstall mysql-server chown -R mysql:mysql /var/lib/mysql
I don’t know how, but somehow the permissions get changed and mysql can no longer operate, or a reinstalled mysql still can’t see the tables. They are not gone, they are there. mysql can’t see them and that can be fixed.
Note: Some complained that if they do:
apt-get install mysql or apt-get remove mysql
They get the error that the package can’t be found. Something like:
# apt-get remove mysql Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package mysql
That has nothing to do with this. This happens because the package for mysql in the repositories is mysql-server and not mysql alone. Doing apt-get install mysql-server will work.