How to backup database on localhost when cannot connect to MySQL?

I’m having ‘HY000/2002): connection refused‘ issue with Lampp on Linux Mint on localhost.
It just started to act this way with no known reason.
I’ve spent hours to fix the problem, no solution yet.

So I decided to backup my databases, and re-install the whole thing.

But here’s the trap: how can I backup my databases with no access to MySQL?
PhpMyAdmin is not working at all.

Thank you for any advice.

Answer

The error message suggests that your MySQL database is not running at all. You should check the logs, they surely contain something about why the database wasn’t started. The easiest way of this is issuing the journalctl -x -u mysql command right after service mysql start.

If you still can’t figure out what went wrong, backup all the directories from /var/lib/mysql/, except the mysql/ and performance_schema/ directories.

After installing a new mysql server, stop it, and copy back the directories saved above. Be sure to maintain the correct file ownership.

If you’re done, start the mysql server. You should see the databases with the root user, but not with anyone else. You can add a user who can access the database with the usual

GRANT ALL PRIVILEGES ON theDatabase.* to theUser identified by "thePassword";

command.

Also note that this is not the way to backup and restore a database. It probably works, but it might not. You should create a proper backup before something bad happens, i.e. just before you start using the database.

Attribution
Source : Link , Question Author : Farkas , Answer Author : Lacek

Leave a Comment