I want to completely remove and re-install mysql on Ubuntu 11.10. I've tried removing it by running:

apt-get remove --purge 'mysql-.*'

But when I re-install it, the old databases are still there, so it obviously wasn't completely removes. How do I remove:

  • the server
  • databases
  • configuration files
  • removing packages won't remove your databases, you will need to delete them manually. You can find database files in /var/lib/mysql – Dmitry Alexeyev Mar 14 '12 at 19:53
  • @DmitryAlexeyev, I beg to differ the purge code in /var/lib/dpkg/info/mysql-server-5.1.postrm clearly has a block of code in place that should be removing /var/lib/mysql if the purge executed properly. – Zoredache Mar 14 '12 at 19:59
  • 1
    @Zoredache You are correct; however, the logic in that script is bad. It only removes (with prompting) /var/lib/mysql if /usr/sbin/mysqld if it isn't executable. Alas, that file is provided by mysql-server-core-5.1. Because mysql-server-5.1 depends on mysql-server-core-5.1, during a removal mysql-server-5.1 is removed first; thus /usr/sbin/mysqld will still exist and the data directory won't be removed. (Verified by running dpkg --force-depends --purge mysql-server-core-5.1 and then dkg --force-depends --purge mysql-server-5.1. N.B. this is not a solution to the question.) – Mark Wagner Mar 14 '12 at 23:02

Delete the default MySQL data directory is /var/lib/mysql. And finally delete the configuration directory that resides in /etc/mysql.

Reinstall and you should be good to go!

  • oh, is that an ubuntu packaging thing?, I have the mysql configuration file as /etc/my.cnf – Tom H Mar 14 '12 at 20:01
  • Although the paths might vary a little bit, the general thumb rule is configuration lies inside /etc. – Shyam Sundar C S Mar 14 '12 at 20:06

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.