16

I had to reboot in the middle of a large data import. I only have one mysql database, which has now been corrupted.

How can I completely remove mysql and reinstall it? I've tried apt-get purge mysql-server, then removing /var/lib/mysql/* and reinstalling, but apt-get does not prompt me for a root name and password nor does it recreate the /var/lib/mysql files. How can I reinstall?

cwd
  • 44,479
  • 71
  • 146
  • 167

2 Answers2

21

You should do the following:

apt-get purge mysql-server mysql-common mysql-client-<version>
rm -rf /var/lib/mysql
rm -rf /etc/mysql*

Then you can reinstall in full.

Karlson
  • 5,845
  • 32
  • 51
  • 1
    thanks! also had to add the version to mysql-server- – cwd Dec 24 '11 at 06:11
  • +1 for mentioning removal of /var/lib/mysql . Keeping that can disallow you performing clean install because it seems it keeps some information about the upgrade. – dimir Feb 26 '16 at 13:08
1

It's much easier to execute this:

sudo mysqld --initialize