Today I tried to drop a database in mysql
DROP DATABASE db_name;
Which resulted in a error: “ERROR 2013 (HY000): Lost connection to MySQL server during query”. At that point everything started to go wrong, to the point where the MySQL server went completely down and I was unable to run it again. In short this is how things happened:
- Try to drop the database, which resulted in an error
- Keep trying to drop it, which resulted in the same error.
- Try increasing the net_read_timeout and net_write_timeout on the server, as well as –connect-timeout in the mysql client. No luck.
- Search the web, find no useful advice, but found a possible reason “data corruption”
- Try to recover data with a backup of the database from the production server. Shit went dow!
- The server stopped and refuse to start again. Following the instructions in the stop error lead me to new search terms.
- We have a new problem now, do more web searching.
- Find a useful page which recommended disabling innodb, and setting myisam as the default database engine.
- After doing that, the server worked, but trying to dump the database resulted in an error: ERROR 1010 (HY000): Error dropping database (can’t rmdir ‘./db_name’, errno: 39 “Directory not empty”)
- I decided to manually remove the directory, which removed the database.
- Create the database again and use the backup to restore it.
- Got an error saying that the table ‘table’ already existed. ‘table’ is the first table that the backup file tries to create.
- Try to dump the database, but got the same error as in #9.
- Manually delete the database again, Create it and the do a proper DROP.
- Create the database again and restore from backup. It worked!
I read a few pages during this problem, and found these useful: