Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between `brew services start mysql` and `mysql.server start`

Tags:

mysql

homebrew

I installed MySQL using homebrew brew install mysql, and I noticed that MySQL can be managed with two different methods:

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? 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

Thank you for the help!

like image 472
Nate Avatar asked Apr 14 '17 20:04

Nate


People also ask

What is MySQL server start?

MySQL distributions on Unix and Unix-like system include a script named mysql. server, which starts the MySQL server using mysqld_safe. It can be used on systems such as Linux and Solaris that use System V-style run directories to start and stop system services.

How do I start MySQL server on Mac?

Open macOS system preferences and select the MySQL preference panel, and then execute Start MySQL Server. The Instances page includes an option to start or stop MySQL, and Initialize Database recreates the data/ directory.


1 Answers

According to the help message of brew services, when you run

brew services start mysql

it installs and starts the service formula at login (or at boot if you run the command with sudo). It means you will have now a plist file in ~/Library/LaunchAgents (or in /Library/LaunchDaemons if you run the command with sudo). For mysql, the plist file is the following:

<?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.

when you run

mysql.server start

you directly execute the mysql script located in /usr/local/bin/mysql.server.

The main difference is that with the brew services version, you run mysqld_safe which, according to its man page:

adds some safety features such as restarting the server when an error occurs and logging runtime information to an error log file.

like image 188
Ortomala Lokni Avatar answered Sep 20 '22 11:09

Ortomala Lokni