I have accidentally typed in webserver terminal following command:

sudo apt-get remove apache2 php* mysql* -y

Can i rescue my database tables, without a backup? I know that, for instance, apache does not remove anything (configs) from system on removal, but what about mysql?

  • 4
    Removing mysql packages should not have affected your mysql data files. Jan 28, 2016 at 17:46
  • i know that each time you run "apt-get install mysql-server" it creates new database with new root password.
    – Croll
    Jan 28, 2016 at 17:48
  • Usually apt-get remove is supposed not to touch any configuration files while uninstalling packages. But I don't use mysql and can't tell you if that one has anything special on it...
    – Byte Commander
    Jan 28, 2016 at 18:29
  • Then you should not write this ( i noticed before that i know it creates new database in "install" that's why i am asking and not trying "install" again). Thanks.
    – Croll
    Jan 28, 2016 at 18:35
  • You might want to have a look in the directory /var/lib/mysql/ to check if the databases files are still there. Jan 29, 2016 at 8:39

2 Answers 2


apt-get does not delete data files when you remove a package. It might remove configuration files if you instruct it to purge (but that's not default behavior).

By default, mysql databases reside in /var/lib. Your dbs should be there.


You still can fetch for your database files within:


To access a database_name_1 you previously created, you'll find its path as:


(you'll need su permissions obviously)

  • Good. But how can i restore it, if "install" creates new database?
    – Croll
    Jan 29, 2016 at 18:24
  • you know the location: so you can copy those DB files wherever you want to save them. Later if you install LAMP, you can import those DB files without needing to recreate them again
    – user284234
    Jan 29, 2016 at 18:28

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.