9

I installed mysql@5.7 using brew. After installing, I started the service using brew services start mysql@5.7. Checking using brew services shows its working fine.

In any attempt after the first though, the behavior is different. I run brew services start mysql@5.7 and I get:

Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/505 /Users/Mahmoud/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist` exited with 5.

If I then try to restart the service, using brew services restart mysql@5.7 I get

Stopping `mysql@5.7`... (might take a while)
==> Successfully stopped `mysql@5.7` (label: homebrew.mxcl.mysql@5.7)
==> Successfully started `mysql@5.7` (label: homebrew.mxcl.mysql@5.7)

but an inspection using brew services would show that the service has been stopped:

Name      Status  User File
mysql@5.7 stopped root ~/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist

Stopping the service manually using brew services stop mysql@5.7 and starting again hasn't worked as well.

Tried as well to uninstall using brew uninstall mysql@5.7 and re-installing using brew install mysql@5.7 but the problem persists. I tried looking all around but I don't see anyone having this same problem. Any ideas on how to fix this?

mrateb
  • 2,317
  • 5
  • 27
  • 56

3 Answers3

23

Environment: M1 MPB, OSX 12.4

Spent a full day on this and finally came to a solution that worked.

Stop the service with brew services stop mysql@5.7

Remove the launch agent file rm ~/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist

Unlink the service if it was linked brew unlink mysql@5.7

Uninstall the service brew uninstall mysql@5.7

Then I removed the mysql data directory, suggested above. This wasn't in the /usr/local/var/mysql on my machine, but rather /opt/homebrew/var/mysql

So rm -rf /opt/homebrew/var/mysql

This wasn't the last step for me. Reinstalling at this point gave me a bunch of errors and the brew post install steps failed. Most of the errors pointed to my my.cnf file. I found that removing this file before attempting to reinstall prevented those errors.

I made a backup of this file just in case this caused more issues.

cp /opt/homebrew/etc/my.cnf /opt/homebrew/etc/my.cnf.backup

Then, rm /opt/homebrew/etc/my.cnf

Note: this file may be in a different location on your machine.

Ok, now do a fresh install.

brew install mysql@5.7

brew link mysql@5.7 --force

If you link the package, you can add it to your path following the brew log suggestion. So add, export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH" to your ~/.zshrc.

Verify the service is available with brew services list or brew services.

If you see mysql@5.7 there, go ahead and start it with brew services start mysql@5.7

jaqarrick
  • 256
  • 2
  • 5
  • 3
    This one solved it for me, thanks! – DavidZ Oct 19 '22 at 16:42
  • Yes, this should be marked the answer as it covers the issue more broadly. – Will Mar 20 '23 at 22:27
  • 3
    This did not work for me. M1 Pro, OS: Ventura 13.2.1. Error: `❯ brew services start mysql@5.7 Bootstrap failed: 5: Input/output error Try re-running the command as root for richer errors. Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/mariusz/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist` exited with 5.` – mario199 Mar 23 '23 at 13:47
4

I had this same issue today and noticed I already had data in the /usr/local/var/mysql/ directory, probably from a previous install.

I didn't care about losing anything within the directory so I removed it all rm -rf /usr/local/var/mysql and ran brew uninstall mysql@5.7 and brew install mysql@5.7.

When I next checked brew services list it was already running, something that didn't happen before and it was all working.

DiagnostiX
  • 41
  • 3
  • 1
    Thank you! Been digging into this for hours - this resolved my issue. :) – Matt Mar 01 '22 at 06:31
  • 1
    Didn't do it for me. :( – dauber Mar 12 '22 at 04:25
  • The problem here is that brew uninstall mysql@5.7 uninstalls it for the user and not for the root user, so I kept getting into problems. Only when changed the user to root and uninstalled and re-installed did things get sorted – mrateb Jun 04 '22 at 12:35
0

Here's a key problem that I later discovered with my brew.

As brew services shows above, the user is root, not the current user. This is insanely problematic and was the main cause of this problem. The solution to this was:

  1. sudo su
  2. brew services you should find the services taht are owned by root
  3. brew stop mysql@5.7 brew uninstall mysql@5.7 Those basically uninstall mysql@5.7 for the root user
  4. exit to get back to the user.
  5. brew install mysql@5.7

Now the owner of the service is the current user, and say goodbye to the crazy behavior of brew

mrateb
  • 2,317
  • 5
  • 27
  • 56