[mysql] start MySQL server from command line on Mac OS Lion

I installed mySQL for my Mac. Beside starting the SQL server with mySQL.prefPane tool installed in System Preference, I want to know the instruction to start from command-line. I do as follow:

After

su root

I start the mySQL server by command-line, it produce 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

Please help me!

EDIT:

The reason is here: http://dev.mysql.com/doc/refman/5.5/en/changing-mysql-user.html

A solution is described in the xdazz's answer below.

This question is related to mysql macos command-line osx-lion

The answer is


maybe your mysql-server didn't started

you can try

/usr/local/bin/mysql.server start


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

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


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/


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


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' 

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 

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


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.


For me this solution worked on mac Sierra OS:

sudo /usr/local/bin/mysql.server start
Starting MySQL
SUCCESS!

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.


Simply:

mysql.server start

mysql.server stop

mysql.server restart


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

Examples related to mysql

Implement specialization in ER diagram How to post query parameters with Axios? PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver' phpMyAdmin - Error > Incorrect format parameter? Authentication plugin 'caching_sha2_password' is not supported How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Connection Java-MySql : Public Key Retrieval is not allowed How to grant all privileges to root user in MySQL 8.0 MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client

Examples related to macos

Problems with installation of Google App Engine SDK for php in OS X dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac Could not install packages due to an EnvironmentError: [Errno 13] How do I install Java on Mac OSX allowing version switching? Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) How can I install a previous version of Python 3 in macOS using homebrew? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'"

Examples related to command-line

Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Flutter command not found Angular - ng: command not found how to run python files in windows command prompt? How to run .NET Core console app from the command line Copy Paste in Bash on Ubuntu on Windows How to find which version of TensorFlow is installed in my system? How to install JQ on Mac by command-line? Python not working in the command line of git bash Run function in script from command line (Node JS)

Examples related to osx-lion

commands not found on zsh Why does cURL return error "(23) Failed writing body"? What is the "Illegal Instruction: 4" error and why does "-mmacosx-version-min=10.x" fix it? Location of the mongodb database on mac How do I timestamp every ping result? How to run iPhone emulator WITHOUT starting Xcode? configure: error: C compiler cannot create executables sudo: port: command not found Disable elastic scrolling in Safari Completely uninstall PostgreSQL 9.0.4 from Mac OSX Lion?