简体   繁体   English

`brew services start mysql` 和 `mysql.server start` 之间的区别

[英]Difference between `brew services start mysql` and `mysql.server start`

I installed MySQL using homebrew brew install mysql , and I noticed that MySQL can be managed with two different methods:我使用 homebrew brew install mysql ,我注意到 MySQL 可以使用两种不同的方法进行管理:

brew services start mysql
and
mysql.server start

Is there any difference when starting the service using brew services vs starting it with the normal mysql.server method?使用 brew services 启动服务与使用普通 mysql.server 方法启动服务时有什么区别吗? Or are they basically the same thing, just a different alias?或者它们基本上是同一个东西,只是别名不同?

It appears they both use the same executable: /usr/local/Cellar/mysql/5.7.17/bin/mysqld看起来他们都使用相同的可执行文件: /usr/local/Cellar/mysql/5.7.17/bin/mysqld

Thank you for the help!感谢您的帮助!

According to the help message of brew services , when you run根据brew services的帮助信息,当你运行

brew services start mysql

it installs and starts the service formula at login (or at boot if you run the command with sudo ).它会在登录时安装并启动服务公式(如果您使用sudo运行命令,则在启动时)。 It means you will have now a plist file in ~/Library/LaunchAgents (or in /Library/LaunchDaemons if you run the command with sudo ).这意味着您现在将在~/Library/LaunchAgents (或/Library/LaunchDaemons如果您使用sudo运行命令)中有一个 plist 文件。 For mysql, the plist file is the following:对于mysql,plist文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>KeepAlive</key>
  <true/>
  <key>Label</key>
  <string>homebrew.mxcl.mysql</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/opt/mysql/bin/mysqld_safe</string>
    <string>--bind-address=127.0.0.1</string>
    <string>--datadir=/usr/local/var/mysql</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>WorkingDirectory</key>
  <string>/usr/local/var/mysql</string>
</dict>
</plist> 

it means that by default mysqld_safe is called with the --bind-address=127.0.0.1 and --datadir=/usr/local/var/mysql command line options.这意味着默认情况下mysqld_safe使用--bind-address=127.0.0.1--datadir=/usr/local/var/mysql命令行选项调用。

when you run当你跑

mysql.server start

you directly execute the mysql script located in /usr/local/bin/mysql.server .您直接执行位于/usr/local/bin/mysql.server的 mysql 脚本。

The main difference is that with the brew services version, you run mysqld_safe which, according to its man page:主要区别在于,使用brew services版本,您运行mysqld_safe ,根据其man页:

adds some safety features such as restarting the server when an error occurs and logging runtime information to an error log file.添加了一些安全功能,例如在发生错误时重新启动服务器并将运行时信息记录到错误日志文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM