7

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.

csi
  • 1,555
  • 7
  • 23
  • 42
  • Hello, your problem can have other origin than package re-installation. What do you mean by service not recognized? – Spack Apr 18 '13 at 22:15
  • Check this 2nd question for concerns about WHY did this happen - http://serverfault.com/questions/500746/mysql-stopped-working-error-2002-unknown-instance – csi Apr 18 '13 at 22:35
  • Did 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. – Nikolas Sakic Apr 19 '13 at 03:43

2 Answers2

10

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.

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
Spack
  • 1,604
  • 15
  • 22
  • 1
    Don't use a `apt-get purge` though, purge does remove all the data. – Zoredache Apr 18 '13 at 22:18
  • I learned this the hard way and lost al my data. Always backup everything! – Miguel Mota Oct 21 '17 at 18:32
  • you 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) – mostafaznv Jan 02 '21 at 08:00
-1

backup:

mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

restore:

mysql -u root -p[root_password] [database_name] < dumpfilename.sql

You can also edit the sql backup file in your favorite text editor.

BullShark
  • 64
  • 2