Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
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 6: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 7:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.