Reinstall MySql AND keep existing database tables and data
MySQL database files are stored in /var/lib/mysql. This folder stays untouched when you remove or re-install the MySQL package, but only if you use apt-get remove
. Don't use apt-get purge
, which will remove the files in /var/lib/mysql.
You should also make a database backup. A copy of /var/lib/mysql may not be enough.
Related videos on Youtube
csi
Updated on September 18, 2022Comments
-
csi over 1 year
Please help!
There are server issues and MySql is no longer running on our server (Ubuntu). The service is not recognized and needs to be reinstalled. Unfortunately, the database has not been backed up for 48 hours and that is a lot of information.
How do I reinstall MySql AND keep all my database data? Please note - I can't access mysql at all. I can't use command line mysql nor phpmyadmin.
Thanks in advance and let me know if I am missing important details.
-
Spack about 11 yearsHello, your problem can have other origin than package re-installation. What do you mean by service not recognized?
-
csi about 11 yearsCheck this 2nd question for concerns about WHY did this happen - serverfault.com/questions/500746/…
-
Nikolas Sakic about 11 yearsDid you try restarting Mysql? Keep in mind, Mysql stocks a sock file, mysql.sock I think in /tmp/ usually. It will not restart if that file is still there. You will have to delete that file and restart mysql.
-
-
Zoredache about 11 yearsDon't use a
apt-get purge
though, purge does remove all the data. -
Zoredache about 11 yearsMysqldump requires a working server. Since he mentioned something is broke, I am not sure this will help much.
-
csi about 11 years"Please note - I can't access mysql at all."
-
Miguel Mota over 6 yearsI learned this the hard way and lost al my data. Always backup everything!
-
mostafaznv over 3 yearsyou can purge mysql too. but keep in mind you should take a backup from
/var/lib/mysql
and after installing mysql, you can restore it (you don't need do mysql_secure_installation)