218

To find out the start command for mysqld (using a mac) I can do:

ps aux|grep mysql

I get the following output, which allows me to start mysql server.

/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=...

How would I find the necessary command to stop mysql from the command line?

4

23 Answers 23

361

Try:

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

Or:

sudo mysqld stop

Or:

sudo /usr/local/mysql/bin/mysqld stop

Or:

sudo mysql.server stop

If you install the Launchctl in OSX you can try:

MacPorts

sudo launchctl unload -w /Library/LaunchDaemons/org.macports.mysql.plist
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql.plist

Note: this is persistent after reboot.

Homebrew

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Binary installer

sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
sudo /Library/StartupItems/MySQLCOM/MySQLCOM restart

I found that in: https://stackoverflow.com/a/102094/58768

21
  • 11
    Thanks, /usr/local/mysql/bin/mysqladmin -u root shutdown did the trick.
    – David542
    Jun 18, 2012 at 22:03
  • 5
    If it's a dev environment and no password is defined, this would work: /usr/local/mysql/bin/mysqladmin -u root shutdown
    – laurent
    Aug 31, 2013 at 9:53
  • 2
    the middle option worked, but only with the addition of "service ": service mysqld stop
    – plaidcorp
    Apr 18, 2014 at 4:50
  • 17
    Oh my god, why I use all these above and it's still running? It's like a virus!
    – Zen
    Aug 30, 2014 at 9:07
  • 7
    What if i'm running mysql as $ mysqld? (just in the terminal). How would i kill it then? Because CTRL-C doesn't work.. I know kill would kill it, but just wondering if there's an escape sequence that mysqld listens to.
    – Matej
    Dec 16, 2014 at 5:20
44

There is an alternative way of just killing the daemon process by calling

kill -TERM PID

where PID is the value stored in the file mysqld.pid or the mysqld process id which can be obtained by issuing the command ps -a | grep mysqld.

7
  • 4
    this is a nice to know b/c it actually kills the process after it kept getting respawned when "kill -9 PID" just did not do it.
    – lordB8r
    Sep 11, 2013 at 1:57
  • 2
    @lordB8r what does b/c it mean? I tried kill -9 mysqld(pid) but it restart immediately after that, this is torturing me.
    – Zen
    Aug 30, 2014 at 9:01
  • @Zen Use kill -TERM mysqld(pid) instead and the entire process tree will be killed, not allowing it to be respawned.
    – Pirooz
    Sep 1, 2014 at 23:54
  • 1
    Yes, the operation is safe as RDBs guarantee ACID properties.
    – Pirooz
    Jun 13, 2018 at 4:44
  • 2
    I tried the kill -term PID and it did kill it but if I run ps -a | grep mysqld, the process mysqld is started again with a new PID.
    – 2myCharlie
    Aug 1, 2018 at 20:07
31

I did it with next command:

sudo killall mysqld
20

I found the answer here.

Use

sudo stop mysql
3
  • 1
    This worked for my AWS ubuntu mysql installation. The 'kill -TERM pid' did not work for my case. Thanks.
    – yoshi
    Feb 20, 2016 at 5:05
  • sudo mysql stop for me (Digital Ocean - ghost-512mb-lon1-01).
    – Leo
    Dec 12, 2016 at 16:02
  • I got this error for that: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
    – 2myCharlie
    Aug 1, 2018 at 20:09
20

For Windows, you can run this command directly if mysql/bin is in your path.

mysqladmin -u root -p shutdown
0
20

Worked for me on mac

a) Stop the process

sudo launchctl list | grep -i mysql

If the result shows anything like: "xxx.xxx.mysqlxxx"

sudo launchctl remove xxx.xxx.mysqlxxx

Example: sudo launchctl remove org.macports.mysql56-server

b) Disable to autostart the process

sudo launchctl unload -wF /Library/LaunchDaemons/xxx.xxx.mysqlxxx.plist

Example: sudo launchctl unload -wF /Library/LaunchDaemons/org.macports.mysql56-server.plist

  • Finally reboot your mac

Note: In some cases if you tried "a)" first, you need to reboot again before try b).

19

When mysql was installed with Homebrew, it automatically restarts when killed. You need to use the following command:

brew services stop mysql

PS: If you installed a specific version, it will be [email protected]

2
  • I discovered the same! So simple. I wish brew had just announced it has a services section, and also that such services can't be shut down from the outside with sudo (which, btw, seems sketchy)
    – Mike B
    Dec 14, 2020 at 21:30
  • If it's a specific version, you need to find the specific version using brew services list and then brew services stop [email protected]. See dba.stackexchange.com/questions/124974/… May 11, 2021 at 17:39
14

On OSX 10.8 and on, the control for MySQL is available from the System Configs. Open System Preferences, click on Mysql (usually on the very bottom) and start/stop the service from that pane. https://dev.mysql.com/doc/refman/5.6/en/osx-installation-launchd.html

The plist file is now under /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

3
  • 4
    For the record, I tried all of the above methods and none of them worked to stop the extra MySQL process. Going through System Preferences & searching for MySQL did the trick - thank you!
    – andycrone
    Oct 17, 2016 at 8:25
  • Thanks, this worked. This is also where you find the uninstall button.
    – smcg
    Apr 29, 2019 at 16:12
  • This worked for most: gist.github.com/vitorbritto/0555879fe4414d18569d but to be safe, try Step 7 before Step 6
    – ppostma1
    Apr 29, 2019 at 20:09
10

for Binary installer use this:

to stop:

sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop

to start:

sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

to restart:

sudo /Library/StartupItems/MySQLCOM/MySQLCOM restart
0
7

Try killing mysqld four times in a row. It's the only thing that worked for me...

root@ubuntu:/etc/init# killall -KILL mysqld 
root@ubuntu:/etc/init# killall -KILL mysqld 
root@ubuntu:/etc/init# killall -KILL mysqld 
root@ubuntu:/etc/init# killall -KILL mysqld 
mysqld: no process found

Just keep killing it over and over until you see "mysqld: no process found".

3
  • This seems like a workaround. Why 4 times? Not a good solution.
    – BertC
    Nov 13, 2020 at 12:37
  • Underrated, but it works. Aug 20, 2022 at 23:55
  • The process that wouldn't die....
    – BobRodes
    Sep 22 at 15:07
6

Kill is definitly the wrong way! The PID will stay, Replicationsjobs will be killed etc. etc.

STOP MySQL Server

/sbin/service mysql stop

START MySQL Server

/sbin/service mysql start

RESTART MySQL Server

/sbin/service mysql restart

Perhaps sudo will be needed if you have not enough rights

3

What worked for me on CentOS 6.4 was running service mysqld stop as the root user.

I found my answer on nixCraft.

1
  • The question is about mac
    – Eugene
    Jul 19, 2021 at 18:47
3
/etc/init.d/mysql stop
service mysql stop
killall -KILL mysql mysqld_safe mysqld

When you see the following information, you success

mysql: no process found
mysqld_safe: no process found
mysqld: no process found

I use this to solve the installation problem of MySQL 5.6 in Ubuntu 15.10 using this link.

During this installation, I encounter the problem saying:

"mysqld_safe A mysqld process already exists"

Just completely stop the mysqld, mysqld_safe, mysql solves the problem.

2

If my mysql keeps restarting
sudo rm -rf /usr/local/var/mysql/dev.work.err
mysql.server stop
worked for me.

1
  • mysql.server stop prompted this error: zsh: command not found: mysql.server
    – 2myCharlie
    Aug 1, 2018 at 20:11
2

To stop autostart of mysql on boot, the following worked for me with mysql 8.0.12 installed using Homebrew in macOS Mojave 10.14.1:

rm -rf ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
2

To stop MariaDB and MySQL server instance:

sudo mysqladmin shutdown

To start MariaDB and MySQL server instance:

mysqld &

To change data ownership for MariaDB and MySQL server instance:

sudo chown -R 755 /usr/local/mariadb/data
1
  1. Just go to task manager.
  2. Then in process, search mysqld.
  3. right click on mysqld then click on stop.
  4. with this process you can stop it without using commands.
1

first try this

sudo service apache2 stop

if not, then

sudo mysql stop

if not, then

sudo stop mysql

if not, then

sudo mysqladmin shutdown

I have been there, and I do with many tips, at the end of using tips that I follow will lead me to solved. So if you not solve in this issue, you just do other tips, till your issue get solved. Hopefully it's will help you. Thanks

1

sudo launchctl list | grep -i mysql

sudo launchctl remove xxx.xxx.mysqlxxx

This works for me!

0

For mysql 5.7 downloaded from binary file onto MacOS:

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

Following worked for me on my macbook pro:

brew services stop mysql

Incase if you want to stop all brew services:

brew services stop --all

0

if all else fails, this help me. Every time I tried to kill the process with the last installation it will respawn.

sudo rm -rf /usr/local/var/mysql

brew reinstall mysql

-1

For MAMP

  1. Stop servers (but you may notice MySQL stays on)
  2. Remove or rename /Applications/MAMP/tmp/mysql/ which holds the mysql.pid and mysql.sock.lock files
  3. When you go back to Mamp, you'll see MySQL is now off. You can "Start Servers" again.
1
  • this will give '/Applications/MAMP/tmp/mysql' for UNIX socket file don't exists' in mysql_error_log file Oct 1, 2019 at 15:02

Your Answer

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

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