ERROR 2002 (HY00): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

How can I backup the databases in MySQL 5.6 if it will not run? It will not create an mysql.sock
so I can't do a dump. I have also reinstalled MySQL 5.6 two times without errors and will not create mysql.sock to get the MySQL running to perform the dump / backup. I have the mysql directory renamed to mysql2 at this point. If I can get a MySQL working at all is it possible to move the database folders into the new database directory /var/db/mysql/ and then do the dump? Or will it just work and not have to do the dump at all? The only thing I was able to do successfully without the MySQL able to run is fix all the databases with myisamchk(8) because you don't need MySQL to run to perform it. mysqlcheck is out of the question and mysqldump is out of the question. I need serious help from an expert here. Thanks in advance.

How did this happen? My server was under attack from blog posting bots to the point I couldn't hardly load a site so I rebooted the server and it corrupted the mysql-bin log files and the Mysql indexes to the point that Mysql would not restart. Then I kept getting this error message...
Code:
 ERROR 2002 (HY00): Can't connect to local  MySQL server through socket '/tmp/mysql.sock' (2)
I tried doing a touch mysql.sock and sure they can be created in the tmp folder no problem but when I restart it will not communicate with it. Just keeps showing that error.
 
The socket is only created when the MySQL server is actually running. In order to do that you're going to have to resolve the issues that prevent MySQL from starting.

Uninstalling or reinstalling MySQL isn't going to help, the corruption is in the databases, not the executables.
 
If I can get MySQL to work by creating a new /var/db/mysql/ and move just the folders into it can the databases then be restored or dumped / exported? Or can I move the folders to a new machine into the MySQL database and then be able to do individual exports from each database folder?
 
If i can get mysql to work by creating a new /var/db/mysql/ and move just the folders into it can the databases then be restored or dumped / exported? or can i move the folders to a new machine into the mysql db and then be able to do individual exports from each database folder?
No, all you are doing is moving the corruption around without actually fixing it. The databases themselves are corrupt. No amount of moving is going to fix that.
 
not even if i move a database folder of one of the sites to another server and then do a mysqlcheck on it and then export it to a sitedatabase.sql file?
 
If you move a corrupted database to another MySQL instance or even a completely different host the database is still corrupted and MySQL server will refuse to start.
 
What you're looking for here is mysql recovery. Assuming your engine is innodb, you can edit /usr/local/etc/my.cnf and add this line:
Code:
innodb_force_recovery = 1
Now try to start the service. If it fails to start, re-edit the config file and bump the value, and try again. As soon as you get it started, mysqldump everything, then nuke the db and re-import from your dump. DON'T TRY TO WRITE TO THE DB WHEN IN RECOVERY MODE. JUST GET YOUR DUMP AND EXIT. (And remember to remove the force_recovery line on your clean setup!)

Increasing values of innodb_force_recovery will cause innodb to skip more sanity checks and to try even harder to recover stuff. It helped me get my tables back after I lost a 512-byte HDD sector right in the middle of my innodb file. Check the data afterwards though, because some of my values were messed up.

More info (or just Google):
https://www.percona.com/blog/2008/07/04/recovering-innodb-table-corruption/

EDIT: but if your tables are not innodb (why not?), then this parameter will do nothing...
 
Back
Top