235

I installed mySQL on my Mac. Beside starting the SQL server with mySQL.prefPane tool installed in System Preferences, I want to know the instructions to start from command-line. I do as follows:

After

su root

I start the mySQL server by command-line, but it produces an error as below:

sh-3.2# /usr/local/mysql/bin/mysqld

111028 16:57:43 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql-5.5.17-osx10.6-x86_64/data/ is case insensitive

111028 16:57:43 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!

111028 16:57:43 [ERROR] Aborting

111028 16:57:43 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

1
  • 3
    On macOS, use mdfind mysql.server to see where your server executable is Oct 29, 2015 at 10:35

16 Answers 16

405

Simply:

mysql.server start

mysql.server stop

mysql.server restart

4
  • 21
    this is what I got for this one: . ERROR! The server quit without updating PID file (/usr/local/var/mysql/XXXX.pid).
    – nyxee
    Aug 18, 2017 at 8:56
  • @nyxee You may need to run it with sudo!
    – anuveyatsu
    Aug 23, 2018 at 8:49
  • 2
    I got the same error even with sudo. On mac Big Sur and MySQL 5.7, I needed to stop/start with: sudo launchctl load -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist and sudo launchctl unload -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
    – hamx0r
    Nov 29, 2020 at 23:38
  • Using only "mysql.server start" didn't worked for me. So figured it out merging @BenjaminCrouzier commentary. Like so: I'm using macOS 10.13.6 High Sierra: 1. Use mdfind mysql.server to see where executable files are. 2. Add Alias to my bash file (.zshrc in my case) export MYSQL_SERVER=/usr/local/mysql-8.0.12-macos10.13-x86_64/support-files/ alias mysql.start="sudo $MYSQL_SERVER/mysql.server start" alias mysql.stop="sudo $MYSQL_SERVER//mysql.server stop" alias mysql.restart="sudo $MYSQL_SERVER/mysql.server restart" 3. Source the bash: source ~/.zshrc Done! Feb 5, 2023 at 11:51
213

Try /usr/local/mysql/bin/mysqld_safe

Example:

shell> sudo /usr/local/mysql/bin/mysqld_safe
(Enter your password, if necessary)
(Press Control-Z)
shell> bg
(Press Control-D or enter "exit" to exit the shell)

You can also add these to your bash startup scripts:

export MYSQL_HOME=/usr/local/mysql
alias start_mysql='sudo $MYSQL_HOME/bin/mysqld_safe &'
alias stop_mysql='sudo $MYSQL_HOME/bin/mysqladmin shutdown'
3
  • 2
    It works. But I can't exit the pointer from the performing of the command. How to stop it when the Terminal window is in performing.
    – vietstone
    Oct 31, 2011 at 1:32
  • 12
    Note that this answer does not apply if you installed mysql with Homebrew.
    – cbmanica
    Oct 27, 2013 at 20:23
  • For me it ended up being just "mysqld <action>", the file is located at /usr/local/mysql/bin/mysqld
    – crobicha
    Aug 15, 2016 at 17:22
152

I like the aliases too ... however, I've had issues with MySQLCOM for start ... it fails silently ... My workaround is akin to the others ... ~/.bash_aliases

alias mysqlstart='sudo /usr/local/mysql/support-files/mysql.server start'
alias mysqlstop='sudo /usr/local/mysql/support-files/mysql.server stop' 
6
  • Other answers failed on OSX 10.7.5 w/ latest MySQL install. This one did the trick - thanks! Mar 6, 2013 at 19:30
  • Thanks!! I wanted to start mysql and be able to close the terminal as well and this worked. What is the difference between this way of starting it and the mysqld_safe way?
    – oli206
    Mar 25, 2013 at 12:18
  • 1
    From mysqld_safe vs mysql.server Before mysql.server starts the server, it changes location to the MySQL installation directory, and then invokes mysqld_safe. Mar 26, 2013 at 3:10
  • I did try the command, but it couldn't start, and it seems to be I can't have a pid file. What should I do?
    – ray6080
    Feb 24, 2014 at 8:44
  • 1
    @ray6080 , I think you forgot to type sudo in front of ./mysql.server start. From the support_files directory, the following command works for me. sudo ./mysql.server start
    – Austin A
    Mar 10, 2015 at 15:26
99

As this helpful article states: On OS X to start/stop MySQL from the command line:

sudo /usr/local/mysql/support-files/mysql.server start 
sudo /usr/local/mysql/support-files/mysql.server stop 

On Linux start/stop from the command line:

/etc/init.d/mysqld start 
/etc/init.d/mysqld stop 
/etc/init.d/mysqld restart 

Some Linux flavours offer the service command too

# service mysqld start 
# service mysqld stop 
# service mysqld restart

or

 # service mysql start 
 # service mysql stop 
 # service mysql restart 
1
  • no such file or directory from /usr/local/mysql/support-files/mysql.server stop
    – nyxee
    Aug 18, 2017 at 8:57
83

If you installed it with homebrew, the binary will be somewhere like

/usr/local/Cellar/mysql/5.6.10/bin/mysqld

which means you can start it with

/usr/local/Cellar/mysql/5.6.10/support-files/mysql.server start

and stop it with

/usr/local/Cellar/mysql/5.6.10/support-files/mysql.server stop

Edit: As Jacob Raccuia mentioned, make sure you put the appropriate version of MySQL in the path.

1
  • 1
    yeah!!!!!! i didn't realize i installed it this way! make sure you put the appropriate version of mysql in the path Aug 10, 2016 at 17:16
50

Maybe your mysql-server didn't start.

You can try

/usr/local/bin/mysql.server start
1
  • This works on Mac OSX Big Sur as of January 9, 2022! Jan 9, 2022 at 16:59
32
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop

make alias in .bash_profile

alias start_mysql="/Library/StartupItems/MySQLCOM/MySQLCOM start"
alias stop_mysql="/Library/StartupItems/MySQLCOM/MySQLCOM stop"

and if you are trying to run as root use following safe mode

sudo ./bin/mysqld_safe

if you are still having issues starting, a recommended read: mysql5.58 unstart server in mac os 10.6.5

14

For me this solution worked on mac Sierra OS:

sudo /usr/local/bin/mysql.server start
Starting MySQL
SUCCESS!
2
  • 2
    For me, the path was /usr/local/mysql/support-files/mysql.server
    – undevable
    Dec 29, 2021 at 18:43
  • /usr/local/Cellar/mysql/8.0.29/bin/mysql.server for me. Just depends how you install it. Obviously Cellar is Brew on MacOS Jul 26, 2022 at 9:31
13

My MySQL is installed via homebrew on OS X ElCaptain. What fixed it was running

brew doctor

  • which suggested that I run

sudo chown -R $(whoami):admin /usr/local

Then:

brew update
mysql.server start

mysql is now running

1
  • Don't know why someone downvoted. This happened to me during a brew update. Running brew doctor, and then following the instructions to add a particular path to my bash profile fixed the issues. Thanks for the suggestion.
    – Nostalg.io
    Jul 15, 2016 at 2:33
9

If it's installed with homebrew try just typing down mysql.server in terminal and that should be it. AFAIK it executable will be under /usr/local/bin/mysql.server.

If not you can always run following "locate mysql.server" which will tell you where to find such file.

6

If you have MySQL installed through Homebrew these commands will help you:

# For starting
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

# For stoping
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
1
  • 4
    The LauchAgent for mysql wasn't there by default. Running brew info mysql (which I learned from: stackoverflow.com/a/4622474/459863) stated that I first had to run ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents. After that, it worked. Nov 11, 2013 at 19:47
3

MySql server startup error 'The server quit without updating PID file '

if you have installed mysql from homebrew

close mysql server from preferences of mac

ps ax | grep mysql

#kill all the mysql process running
sudo kill -9 pid

which mysql
/usr/local/bin/mysql
Admins-MacBook-Pro:bin username$ sudo mysql.server start

Starting MySQL
. SUCCESS! 

Admins-MacBook-Pro:bin username$ which mysql

/usr/local/bin/mysql

Admins-MacBook-Pro:bin username$ ps ax | grep mysql

54916 s005  S      0:00.02 /bin/sh 
/usr/local/Cellar/[email protected]/5.7.27_1/bin/mysqld_safe --datadir=/usr/local/var/mysql --pid-file=/usr/local/var/mysql/Admins-MacBook-Pro.local.pid
55012 s005  S      0:00.40 /usr/local/Cellar/[email protected]/5.7.27_1/bin/mysqld --basedir=/usr/local/Cellar/[email protected]/5.7.27_1 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/[email protected]/5.7.27_1/lib/plugin --user=mysql --log-error=Admins-MacBook-Pro.local.err --pid-file=/usr/local/var/mysql/Admins-MacBook-Pro.local.pid
55081 s005  S+     0:00.00 grep mysql
3

On mac Big Sur and MySQL 5.7, I needed to stop/start with:

sudo launchctl load -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

and

sudo launchctl unload -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

This answer came from https://coolestguidesontheplanet.com/start-stop-mysql-from-the-command-line-terminal-osx-linux/

1
  • working on macOS monterray for mysql 8.0.28
    – Mohsin AR
    Mar 8, 2022 at 19:29
1

In my case, I had downloaded the mysql server and installed it but I didn't click on the run server that showed up on the last installer page.

In order to start my server manually in the terminal (without adding aliases), I used this in the terminal and it works.

Start Server:

sudo launchctl load -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

Stop Server:

sudo launchctl unload -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

More info at the link below: https://www.databasestar.com/start-mysql-server/

1

This worked for me (MacOs):

Start MySQL:

sudo /usr/local/mysql/bin/mysqld_safe

Stop MySQL:

/usr/local/mysql/bin/mysqladmin -u root -p shutdown

1
  • This is working. Mac OS Sonoma 14.3.1 and MySQL 8.3 for ARM64 Mar 4 at 16:15
0
111028 16:57:43 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!

Have you set a root password for your mysql installation? This is different to your sudo root password. Try /usr/local/mysql/bin/mysql_secure_installation

1
  • When I ran the above line, it produce: Can't find a 'mysql' client in PATH or ./bin
    – vietstone
    Oct 31, 2011 at 1:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.