How to start MySQL server from command line on Mac OS Lion?
Asked Answered
H

16

236

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

Hotspur answered 28/10, 2011 at 10:5 Comment(1)
On macOS, use mdfind mysql.server to see where your server executable isZaid
T
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'
Towhee answered 30/10, 2011 at 8:9 Comment(3)
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.Hotspur
Note that this answer does not apply if you installed mysql with Homebrew.Refract
For me it ended up being just "mysqld <action>", the file is located at /usr/local/mysql/bin/mysqldAllard
C
405

Simply:

mysql.server start

mysql.server stop

mysql.server restart

Corrigan answered 22/9, 2015 at 7:50 Comment(4)
this is what I got for this one: . ERROR! The server quit without updating PID file (/usr/local/var/mysql/XXXX.pid).Adornment
@Adornment You may need to run it with sudo!Bullfrog
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.plistInning
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!Sufferance
T
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'
Towhee answered 30/10, 2011 at 8:9 Comment(3)
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.Hotspur
Note that this answer does not apply if you installed mysql with Homebrew.Refract
For me it ended up being just "mysqld <action>", the file is located at /usr/local/mysql/bin/mysqldAllard
S
153

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' 
Spies answered 23/7, 2012 at 21:53 Comment(6)
Other answers failed on OSX 10.7.5 w/ latest MySQL install. This one did the trick - thanks!Holocrine
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?Purveyance
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.Spies
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?Skull
@Skull , 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 startSubtemperate
@AustinA wow! I know its an older comment, but thank you! this worked for me (MySQL 8.0.31, MacOS version 12.6.3)Yiyid
C
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 
Cyclometer answered 6/11, 2012 at 12:31 Comment(1)
no such file or directory from /usr/local/mysql/support-files/mysql.server stop Adornment
J
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.

Joost answered 30/5, 2013 at 17:28 Comment(1)
yeah!!!!!! i didn't realize i installed it this way! make sure you put the appropriate version of mysql in the pathOutgrowth
G
50

Maybe your mysql-server didn't start.

You can try

/usr/local/bin/mysql.server start
Gastroenteritis answered 9/12, 2013 at 15:15 Comment(1)
This works on Mac OSX Big Sur as of January 9, 2022!Checkerberry
X
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

Xanthippe answered 30/10, 2011 at 8:16 Comment(0)
M
14

For me this solution worked on mac Sierra OS:

sudo /usr/local/bin/mysql.server start
Starting MySQL
SUCCESS!
Miller answered 12/5, 2017 at 14:16 Comment(2)
For me, the path was /usr/local/mysql/support-files/mysql.serverTrish
/usr/local/Cellar/mysql/8.0.29/bin/mysql.server for me. Just depends how you install it. Obviously Cellar is Brew on MacOSCyanohydrin
B
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

Bonheur answered 10/6, 2016 at 11:27 Comment(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.Sailplane
P
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.

Pliant answered 8/12, 2014 at 10:48 Comment(0)
F
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
Fernald answered 13/8, 2013 at 9:19 Comment(1)
The LauchAgent for mysql wasn't there by default. Running brew info mysql (which I learned from: https://mcmap.net/q/86160/-brew-install-mysql-on-macos) stated that I first had to run ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents. After that, it worked.Financier
B
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
Boy answered 30/10, 2019 at 19:32 Comment(0)
I
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/

Inning answered 29/11, 2020 at 23:39 Comment(1)
working on macOS monterray for mysql 8.0.28Avictor
A
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/

Acidulous answered 19/1, 2023 at 23:46 Comment(0)
D
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

Deibel answered 1/5, 2023 at 12:58 Comment(1)
This is working. Mac OS Sonoma 14.3.1 and MySQL 8.3 for ARM64Levanter
A
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

Ahab answered 30/10, 2011 at 9:0 Comment(1)
When I ran the above line, it produce: Can't find a 'mysql' client in PATH or ./binHotspur

© 2022 - 2024 — McMap. All rights reserved.