MacOSX:启动时自动启动 mysql
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8014500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MacOSX: autostart mysql on boot
提问by Tim Baas
I just installed mysql in terminal through homebrew.
我刚刚通过自制软件在终端中安装了 mysql。
Now when I try to connect to mysql it fails, but after I run mysqld
it works..
现在,当我尝试连接到 mysql 时它失败了,但是在我运行后mysqld
它可以工作..
So what I need to do now is run mysqld when I boot my Mac.
所以我现在需要做的是在启动 Mac 时运行 mysqld。
I've searched Google for mysqld autoload at startup
etc. but couldn't find the right answer.
我在谷歌上搜索过mysqld autoload at startup
等等,但找不到正确的答案。
Hope someone can point me in the right direction.. Thanks!
希望有人能指出我正确的方向..谢谢!
回答by mipadi
brew info mysql
gives you the instructions for loading MySQL at startup, but here's all you need to do:
brew info mysql
为您提供了在启动时加载 MySQL 的说明,但您只需要执行以下操作:
mkdir -p ~/Library/LaunchAgents
cp `brew --prefix mysql`/*mysql*.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/*mysql*.plist
回答by Alejandro Iván
Nowadays, brew info mysql
gives you this statement:
如今,brew info mysql
给你这样的声明:
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
现在启动 mysql 并在登录时重新启动: brew services start mysql
或者,如果您不想要/不需要后台服务,您可以运行:mysql.server start
So running brew services start mysql
will ensure it will run as a service and re-start on every login.
因此运行brew services start mysql
将确保它作为服务运行并在每次登录时重新启动。
If you run that command with sudo
:
如果您使用sudo
以下命令运行该命令:
sudo brew services start mysql
will make the service run on bootand not after logging in, which is more useful for servers.
将使服务在启动时运行而不是在登录后运行,这对服务器更有用。
回答by Rubinous
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:
在本文发布之日,由于安装了 Homebrew 的 MySQL 5.6.13,Mipadi 的回答对我来说失败了。但我brew info mysql
按照他的建议进行了检查,它给了我一个可行的解决方案:
> ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
回答by Bruno
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/mysql/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
回答by mikoop
I have brew install of MYSQL.
我有 MYSQL 的 brew 安装。
type
类型
brew info mysql
and follow the instructions given:
并按照给出的说明进行操作:
To have launchd start mysql at login:
要在登录时启动 mysql:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
回答by Mateus Mendon?a
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:
您不再需要设置 plist。截至 2017 年 10 月的最新版本 brew (1.3.4),您只能运行:
brew services start <service_name>
brew services start <service_name>
and it will auto start every time you restart your computer. The command brew info
gives you this
每次重新启动计算机时它都会自动启动。命令brew info
给你这个
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
现在启动 mysql 并在登录时重新启动: brew services start mysql 或者,如果您不想要/不需要后台服务,您可以运行:mysql.server start
回答by JP Duffy
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