Tryst with Laravel – Quick recovery from Homestead MySql Crash
Tushar Bohra
January 5, 2018

I am a huge fan of the Homestead development environment. Among all the other benefits that it offers the robust set of pre-installed packages makes working with it a huge delight. Also the peace of mind that comes with it being a complete separate installation not affecting resources on other system are unparalleled.

 

Today, I ran into a issue with the bundled MySql installation. I was importing a pretty huge database from our testing server into my local database hosted on the Homestead that I use to run my project. In between that, my system froze and crashed. It came back up again quickly and I restarted my Homestead box which occurred without any error. Went to Sequel Pro and the interface refused to connect with the database.

 

Restarted again and then reprovisioned the box, which failed with a MySql error. Went into the box and checked out the error logs and found the issue.

homestead mysql error log after system crash

MySql error log

 

Now, I had some important assignment to work on, and needed the system up and running quickly. Since this was my development system and the database was not critical, the following steps recovered my system very quickly-

 

SSH into the Homestead box and clear MySql library files

vagrant ssh
sudo -i
cd /var/lib/mysql
rm -f ib*

Create a new database from the mysql client of choice

Update the .env file to connect to the new database

Move to console and run migrations and seeders

php artisan migrate
php artisan db:seed

 

And we are up and running very quickly. Not the cleanest way to do and if there is time or the data is critical, we can certainly explore recovery options. This is handy when time is of essence over the database.