0

I had installed mysql, mysql-server, and mysql-devel via yum:

yum install mysql mysql-server mysql-devel

I had created some databases and users and ended up breaking some tables, so I attempted to remove mysql so I could make a fresh install.

I issued the following commands:

#To remove the packages: 
yum remove mysql mysql-server mysql-devel
#To remove the data
rm -rf /var/lib/mysql

Now, after I install mysql, mysql-server, and mysql-devel again and then run mysql, the mysql.user table includes multiple 'root' users and the old databases are still available.

I have ran the following trying to find any configuration files or whatnot for mysql, to no avail:

find . -name \*.sql\*
whereis mysql
whereis sql
grep -hilr "old_database_name" *
grep -hilr "mysql" *

What am I missing?

Mike Moore
  • 223
  • 2
  • 7
  • 15

1 Answers1

2

The packages don't erase the data directory, /var/lib/mysql, when the packages are removed. So, what you would want to do is remove the packages, then:

mv /var/lib/mysql /var/lib/mysql.old

Now re-install the packages, and the databases should be back to their pristine state. Once you have verified that you don't need any data in the old databases, you can then remove them with:

rm -rf /var/lib/mysql.old

This two-step process also has the benefit that if you accidentally re-run either of those commands, say while going back through the command-line history, that neither one on their own will destroy production data.

Sean Reifschneider
  • 10,370
  • 3
  • 24
  • 28
  • I had ran `rm -rf /var/lib/mysql` (I accidentally typed it incorrectly in the original post and have just edited it). Unfortunately, the old databases from the previous install are still there after re-installing mysql. – Mike Moore Aug 26 '11 at 06:50
  • 2
    Do *NOT* move /var/lib/mysql *AFTER* you re-install the packages, do it before, otherwise you are "pulling the rug" out from underneath MySQL. So start again, remove the packages, mv /var/lib/mysql out of the way, and then re-install. At that point your databases should be as fresh as if you had done a brand new OS install. This would also completely clear out the mysql.user table, so anything that exists after that is part of the base install. Be aware that if you remove all users you may no longer be able to connect to the database. You probably don't want to do this. – Sean Reifschneider Aug 26 '11 at 07:10