MySQL Problems – a complete reinstall

I rebooted an Ubuntu 12.04 server after upgrading the kernel and MySQL.  However, I found that the new MySQL would you not start. When I tried:

sudo service start mysql

I got:

start: job failed to start

There were no errors appearing in the /var/log/mysql/error.log and so there was no information to help debug it.  I found this post and tried every single one of the solutions.  When I removed mysql-server-5.5 using:

apt-get –purge remove mysql-server
rm /etc/mysql/ -R

I found the when I reinstalled mysql-server the installation would fail saying:

Unable to set password for the MySQL “root” user  An error occurred while setting the password for the MySQL administrative user. This may have happened because the account already has a password, or because of a communication problem with the MySQL server.

I then got stuck because I could no longer remove MySQL because it was only partially installed.  Every time I tried to remove it, it would ask me to put in a new root password which I obviously could not do.  The solution is to use dpkg to purge the partially installed package:

dpkg –purge mysql-server-5.5

Then I tried reinstalling again and got:

Can’t find file: ‘./mysql/host.frm’ (errno: 13)

Basically, the solution to these problems is a complete purge of MySQL and removing ALL of it and start again.  I found what mysql related packages I have install by running:

dpkg –get-selections | grep mysql

and found I had:

libdbd-mysql-perl
libmysqlclient18
mysql-client-5.5
mysql-client-core-5.5
mysql-common
mysql-server
mysql-server-5.5
mysql-server-core-5.5
mysqltuner
php5-mysql

I removed all them!

apt-get –purge remove mysql-server
apt-get –purge remove mysql-client
apt-get –purge remove mysql-common
…… etc …. etc…

Then cleared the apt-get cache and removed the mysql config and data directories (I have a backup of the data from the night before.)

apt-get autoremove
apt-get autoclean
rm /etc/mysql/ -R
rm /var/lib/mysql/ -R

Then reinstalling mysql-server and the other packages.

apt-get install mysql-server
etc….

What a massive waste of time!  Oh well – I hope this post helps someone else out of this pickle.

54 thoughts on “MySQL Problems – a complete reinstall

  1. After several hours of struggling, this article really did solve my problem. Thanks!
    I think that my problem was that mysql workbench made the uninstall of mysql-server uncomplete. After removing all mysql related packages as stated above, I finally got it back together again.

  2. James, you saved my day with this post.
    I spent the day struggling with this problem. I tested dozens of tips from other people, but one that really solved the problem was his.
    Many thanks for the help!

    1. Thanks for the feedback. Your approach might be simpler but I found alot of solutions on the internet that appear to work… but don’t. I wrote this post because I wasted so much time trying to recover from the situation.

      If a few people could try this and confirm that it works and fixes their problems then i will put this in the main post as an option.

  3. Actually I think the issue was with the /etc/mysql/my.cnf. Upgrading mysql doesn’t work with the old my.cnf. Use the one that comes with the debian package cp my.cnf.dpkg-dist my.cnf

    1. Great. This makes sense. If someone could try this out then and check it works then I will put this in the main post.

  4. Simply uninstalling doesn’t resolve problem for my case. I also removed file /etc/my.cnf and reinstalled and then it worked. 🙂

  5. I just wanted to say that some people just can communicate better than others. Thanks for being a little more meticulous in your documentation. I wasted so much time on other sites before coming here.

  6. Many thanks, this worked on Raspbian on a Raspberry Pi too. I think deleting the content from /var/lib/mysql/ is the most important step which I am missing in other tutorials. But anyway, mysql-server is up and running!!

  7. Thank you very much for the help. I followed this tutorial and was still having the message unable to set up mysql root password, so could not start mysql because the service was never configured.
    My problem was that by mystake I changed ownership and permission of /tmp folder when deleting data for space issue.

    I am just writing this if anyone has the same problem, it seems mysql uses /tmp folder so be sure you got the right permissions in that folder

  8. This post helped!

    Rest of the posts on the internet do not mention the next two commands:

    rm /etc/mysql/ -R
    rm /var/lib/mysql/ -R

    These seem to be the critical steps which helped solve the issue for me.

    autoremove/autoclean is mentioned in the other solutions but they did not solve the issue.

    Thanks a lot again!!

    1. Thanks for the feedback. Just to be clear to anyone reading this. The rm /var/lib/mysql command will delete all your MySQL databases data. You should make sure that you have backups or simply don’t care what is in the database.

Leave a Reply