MacOSX: autostart mysql on boot
Solution 1
brew info mysql
gives you the instructions for loading MySQL at startup, but here's all you need to do:
mkdir -p ~/Library/LaunchAgents
cp `brew --prefix mysql`/*mysql*.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/*mysql*.plist
Solution 2
Nowadays, brew info mysql
gives you this statement:
To have launchd start mysql now and restart at login: brew services start mysql
Or, if you don't want/need a background service you can just run: mysql.server start
So running brew services start mysql
will ensure it will run as a service and re-start on every login.
If you run that command with sudo
:
sudo brew services start mysql
will make the service run on boot and not after logging in, which is more useful for servers.
Solution 3
Mipadi's answer failed for me with MySQL 5.6.13 installed with Homebrew on the date of this post. But I checked brew info mysql
as he suggested and it gave me a working solution:
> ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Solution 4
You don't need to setup a plist anymore. The latest version of brew (1.3.4) as of Oct 2017, you can only run:
brew services start <service_name>
and it will auto start every time you restart your computer. The command brew info
gives you this
To have launchd start mysql now and restart at login: brew services start mysql Or, if you don't want/need a background service you can just run: mysql.server start
Solution 5
Followup to Alejandro that couldn't fit in a comment.
Check which services are user (login) and root (boot) with this:
$ brew services list
Name Status User Plist
chronograf started jacob /Users/jacob/Library/LaunchAgents/homebrew.mxcl.chronograf.plist
grafana started jacob /Users/jacob/Library/LaunchAgents/homebrew.mxcl.grafana.plist
influxdb started root /Library/LaunchDaemons/homebrew.mxcl.influxdb.plist
kapacitor stopped
mariadb started jacob /Users/jacob/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
memcached started jacob /Users/jacob/Library/LaunchAgents/homebrew.mxcl.memcached.plist
telegraf started jacob /Users/jacob/Library/LaunchAgents/homebrew.mxcl.telegraf.plist
Related videos on Youtube
Tim Baas
Self-made entrepreneur and programmer. Current projects: Packhouse ServiceBook Swapp Past projects: Buildion The Flying Dutchmen No Dutch No Glory Is it a Bird BaasCommandeur Heren Kaktus
Updated on July 09, 2022Comments
-
Tim Baas almost 2 years
I just installed mysql in terminal through homebrew.
Now when I try to connect to mysql it fails, but after I run
mysqld
it works..So what I need to do now is run mysqld when I boot my Mac.
I've searched Google for
mysqld autoload at startup
etc. but couldn't find the right answer.Hope someone can point me in the right direction.. Thanks!
-
joanwolk almost 12 yearsI believe this is only true if you've installed mysql via brew, but it's great if you have!
-
mtkopone over 11 yearsIn my latest installation, the plist file is named: homebrew.mxcl.mysql.plist
-
chhantyal over 9 yearsAnd if you have Mariadb installed, file name is : homebrew.mxcl.maraidb.plist
-
l008com about 6 yearsThis is the ONLY answer that actually answers the question, and launches the server at BOOT and not LOGIN. It creates the right .plist in the right location. This should really be marked as the right answer... even though it's not actually working for me. But I think that is a separate issues.
-
RonLugge over 4 yearsWhile this answer is historically accurate, the more recent
brew services start
command is the modern solution, easier to work with than the arcane launchctl -
gone almost 4 yearsShould this go in
/Library/LaunchAgents
or/Library/LaunchDaemons
? I think the later. -
Oleksii Nezhyborets over 2 yearsWon't allow to do sudo because "Running Homebrew as root is extremely dangerous and no longer supported". How do I do it on boot now?
-
Alejandro Iván over 2 yearsLooks like there's no way unless
root
owns thebrew
executable. You'll probably need to go theLaunchDaemons
way from other answers. IMHO this is the worst decision people from Homebrew has made. We know what we're doing, there should at least be a toggle do disable that stupid enforcement.