Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have MySQL installed on my localhost. What happens if I have a problem with mysql and I want to re-install it again? Do I lose my existing databases?

share|improve this question
Wouldn't it be better to explain your problems wit mysql. So people can try to help you fix those. Re installing is more a windows-way of solving problems. – rechengehirn Dec 4 '13 at 17:47
Being cautious, it's a good idea to backup your databases first. You can use mysqldump with the --all-databases option.… – Progrock Dec 4 '15 at 9:38

No, reinstalling mysql-server will not delete you database files, only delete the package files of mysql-server. You will be able to access your files(database) after you re-install the server.

To purge and install mysql-server:

sudo apt-get purge mysql-server
sudo apt-get install mysql-server

If you want to delete the database too, you must delete it first before you remove mysql. To delete the database cleanly, on the mysql prompt type:

drop database <database_name>

I found another way to delete the database files, but I am not sure whether this is a clean way to delete the database, so take it with a pinch of salt:

From a question on stackoverflow:

It(The location of the database files) is installation specific, but if you've /var/lib/mysql , then:

  • MyISAM tables will be stored in individual files in /var/lib/mysql/databasename/
  • InnoDB resides in /var/lib/mysql/ibdata (unless you've used the innodb_per_table setting, in which case it's stored much like for MyISAM tables)

So check the location of your databases in these two locations and delete the directory of the databases(requires superuser privileges to read and delete).

share|improve this answer
How do I do it in a way to delete my files, if I wanted to? – Aditya M P Mar 6 '14 at 6:57
@adityamenon: Edited to reflect that, thanks! – i08in Mar 6 '14 at 10:21
Thank you, too! :) – Aditya M P Mar 6 '14 at 13:19

Use apt-get remove. Don't use apt-get purge, which will remove the files in /var/lib/mysql.

share|improve this answer

Your Answer


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.