Ubuntu 10.x completely remove and clean MySQL installation

In my attempt to move the MySQL datadir I have a messed up MySQL installation. Here’s how I’ve completely removed MySQL 5.1 from Ubuntu 10.x. i have a messed up installation and need to completely remove MySQL and re-install it. Warning, this will delete *everything* associated with MySQL on ubuntu! It does give you a fresh install!

using apt:
apt-get –purge remove mysql-server
apt-get –purge remove mysql-client
apt-get –purge remove mysql-common

apt-get autoremove
apt-get autoclean

using aptitude (some people claim aptitude does a better job of removing dependencies):
aptitude remove mysql-client
aptitude remove mysql-server
aptitude remove mysql-common

see if anything depends on the installed packages
apt-cache rdepends mysql-server
apt-cache rdepends mysql-client

if you’ve changed apparmor settings change them back inside here:
pico /etc/apparmor.d/usr.sbin.mysqld

delete preferences(the next find command will delete everything):
rm -rf /etc/mysql

find all files with “mysql” on / and delete them:
find / -iname ‘mysql*’ -exec rm -rf {} \;

after all of the above do a clean install
aptitude install mysql-server mysql-client

check to see if mysql is running:
service mysql status

and you should get the response running

mysql start/running, process 3296

check with mysqladmin:

mysqladmin -u root -p status

30 thoughts on “Ubuntu 10.x completely remove and clean MySQL installation”

  1. Thanks a ton! Your post saved me, i was struggling from hours to do a fresh install.

  2. Thanks, have been messing around with this for days. Worked a treat

  3. Thanks for this. I’ve been locked out of mysql for days now. This really helped.

    Cheers.

  4. absolute legend. been wresting with a lamp mysql installation for a day now, wish I had just done this at the start!

  5. Good resume! I had only one issue because of typing without thinking. I have a dual boot with a WAMP under Vista on the other SO, so when rm -rf inside the find… it looked into my Media/Data disk… well… I will have to reinstall WAMP xD

  6. And if you want to get rid of the database files themselves, you may need to delete /usr/local/mysql or /var/lib/mysql or somewhere else depending on your distro.

  7. Great fix, man. I originally used aptitude to unistall mysql. However, I ran into some trouble. It didn’t seem to uninstall everything..but, apt-get did the trick. I’m new to Linux, so it was probably something I did

  8. Thanks a lot! 2 hours I fight with mysql fixing after ubuntu upgrade to 12.04.
    And you post help me to win.

  9. It doesn’t work when the mysql.sock is missing!! tried to uninstall because mysql.sock was missing, and i couldn’t porperly uninstall mysql!!

  10. After literally days of searching the web for a fix to a suddenly non-functioning MySQL installation, I found your fix. Excellent! It worked. I’m back in business. I won’t even attempt to list all the other things I tried first. Muchas gracias.

  11. I recommend NOT to use the

    find / -iname ‘mysql*’ -exec rm -rf {} \;

    – it will delete ALL files starting with the name “mysql” on your system – no matter if they have anything to do with the MySQL package or not.

    For example: If you have a file like:

    mysql-my-very-important-thesis.docx

    it will be deleted.

  12. Hi
    Thanks alot man , i was try to work on Yii , one of the PHP frameworks and long story short my mysql try to mess with me until i find your article and it work great .

  13. WHen i do a fresh install it give me this..
    mysqladmin: connect to server at ‘localhost’ failed

    error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’

    Check that mysqld is running and that the socket: ‘/var/run/mysqld/mysqld.sock’ exists!
    any fix ?

Leave a Reply

Your email address will not be published. Required fields are marked *