Homebrew MySql Start Issue

If you ended up sudden mysql not starting on your mac machine. Most likely this is due to unintentional mysql upgrade during homebrew update. Reverting to previous mysql version quickly fix issue. If you wish to try this make sure to take backup of mysql data folder first. Below are the error message I was getting when I tried to run mysqld manually. I tried every possible method to recover but none of them worked.

mysqld: Can’t open file: ‘mysql.ibd’ (errno: 0 – )
[ERROR] [MY-012574] [InnoDB] Unable to lock ./ibdata1 error: 35
Failed to initialize DD Storage Engine

In my case New MySQL version was MySQL 8.0.17_1 while old version was MySQL 5.7.

1. Backup MySQL data folder. This is most important. In case something goes wrong you will have data backup folder to recover some other way. If you have installed mysql via homebrew then data folder will be /usr/??local?/?var/mysql

2. Open Terminal and Uninstall existing version by running following command.

brew uninstall mysql

3. Install MySQL 5.7

brew uninstall mysql@5.7

4. Link MySql Version

brew link --force mysql@5.7

5. Start MySQL service

brew services start mysql@5.7

All done. All my databases and tables come back mysql started successfully after reverting from MySQL 8 to MySQL 5.7. Hope this help others too.

Written by Bala Krishna

Bala Krishna is web developer and occasional blogger from Bhopal, MP, India. He like to share idea, issue he face while working with the code.