217

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?

David542
  • 104,438
  • 178
  • 489
  • 842
  • 1
    Have you checked out http://stackoverflow.com/questions/100948/how-do-stop-mysql-on-a-mac-os-install?rq=1 – dhable Jun 18 '12 at 21:36
  • This work for me: http://askubuntu.com/questions/529302/how-to-stop-mysqld-process Maybe it will work for you too bro. []'s – lam3 Jun 12 '15 at 15:51
  • 1
    The question was for a Mac. – Snowcrash Feb 15 '17 at 11:53
  • If you're connected via the `mysql` client, you can just [type `SHUTDOWN` at the prompt](https://dev.mysql.com/doc/refman/8.0/en/shutdown.html). – chb Nov 27 '18 at 20:07

23 Answers23

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

Community
  • 1
  • 1
squiter
  • 5,711
  • 4
  • 24
  • 24
  • 11
    Thanks, `/usr/local/mysql/bin/mysqladmin -u root shutdown` did the trick. – David542 Jun 18 '12 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 '13 at 09:53
  • 2
    the middle option worked, but only with the addition of "service ": service mysqld stop – plaidcorp Apr 18 '14 at 04:50
  • mysqladmin is sometimes in /usr/bin . Try, as root: `/usr/bin/mysqladmin -u root -p shutdown` – barbacan Jul 28 '14 at 07:58
  • 17
    Oh my god, why I use all these above and it's still running? It's like a virus! – Zen Aug 30 '14 at 09:07
  • @Zen do you use OSX?! If yes, you probaly set the LauchCTL system to make MySQL running all the time, look at `https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/launchctl.1.html` to learn more about! – squiter Aug 30 '14 at 14:09
  • 1
    @zen you can check in `~/Library/LaunchAgents`, `/Library/LaunchAgents`, `/Library/LaunchDaemons` , `/System/Library/LaunchAgents` or `/System/Library/LaunchDaemons` look for any file with mysql in name. – squiter Aug 30 '14 at 14:10
  • @zen I found a link that helps you: http://stackoverflow.com/questions/100948/how-do-you-stop-mysql-on-a-mac-os-install – squiter Aug 30 '14 at 14:11
  • 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 '14 at 05:20
  • @matejkramny did you mean when you use a mysql client in terminal? `mysqld` is a daemon version with runs in background and can be stopped by `sudo mysqld stop`. If you are using as client, you must to send `quit` command and hit enter. – squiter Dec 17 '14 at 02:18
  • @BrunnoDosSantos i meant when mysqld runs in foreground in a terminal. Sorry for badly wording that. – Matej Dec 17 '14 at 09:23
  • @matejkramny you can send `quit` to exit client and shotdow server with one of options of answer. – squiter Dec 17 '14 at 15:26
  • @BrunnoDosSantos may I check why you run `unload` and then `load` again? – ericn Jan 12 '15 at 06:52
  • @fuzzbee I think that I don't explain in a good way. Sorry about that. That kind of Launchctl is used to run software in boot, so if you want to stop you can use unload at once. And if you want mysql run again when you boot you system use load. (sorry about bad english) – squiter Jan 12 '15 at 14:06
  • i had the same situation today. Even if i had **su root** in my terminal , then executed: `service mysql stop` - that still brought up : 'unknown job: mysql', only when i ran the complete: `sudo service mysql stop` - it worked. – devplayer Aug 25 '16 at 10:09
  • right, so executing service mysql with the wrong user rights brings up 'unknown job: mysql', the environment is not changed unless the -l (or -) is provided to `su` , so doing `sudo root` before `service mysql stop` is not enough – devplayer Aug 25 '16 at 10:16
  • 'sudo mysqladmin shutdown' is what did it for me – Greg Blass Apr 12 '17 at 12:07
  • 'sudo mysqld stop' worked in my Mac with high sierra – Leonardo Rignanese Feb 27 '18 at 09:57
  • None of the commands above works for me. When I type in sudo lsof -nP +c 15 | grep LISTEN it still shows the mysqld running listening to port 3306. – 2myCharlie Aug 01 '18 at 20:05
  • For me (Mac OS, 5.7.38 installed via Brew), `mysqld stop` just tries to run it and then complains that it's already running. `mysql.server stop` did the trick. – Matthew Read May 04 '22 at 22:18
  • `brew services stop mysql` worked for me – Jasmeet Singh Jun 02 '22 at 19:38
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.

Pirooz
  • 1,268
  • 1
  • 13
  • 24
  • 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 '13 at 01: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 '14 at 09:01
  • @Zen Use `kill -TERM mysqld(pid)` instead and the entire process tree will be killed, not allowing it to be respawned. – Pirooz Sep 01 '14 at 23:54
  • Is this safe, cannot this lead to data corruption? – W.M. Apr 19 '18 at 16:32
  • 1
    Yes, the operation is safe as RDBs guarantee ACID properties. – Pirooz Jun 13 '18 at 04: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 01 '18 at 20:07
  • Use `kill -TERM mysqld(pid)` instead. If that does not work, there may be a respawning mechanism in place on your machine. Some places to check and verify if that is the case are suggested here: https://unix.stackexchange.com/questions/163603/how-to-find-source-of-spawning-process – Pirooz Aug 03 '18 at 01:40
31

I did it with next command:

sudo killall mysqld
Vittore Gravano
  • 706
  • 6
  • 22
20

I found the answer here.

Use

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

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

mysqladmin -u root -p shutdown
Pang
  • 9,564
  • 146
  • 81
  • 122
Lokinder Singh Chauhan
  • 2,326
  • 1
  • 20
  • 23
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).

Community
  • 1
  • 1
ceskamx
  • 246
  • 2
  • 4
18

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 mysql@X.X

Kevin Danikowski
  • 4,620
  • 6
  • 41
  • 75
BertC
  • 2,243
  • 26
  • 33
  • 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 '20 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 mysql@5.7`. See https://dba.stackexchange.com/questions/124974/mysqld-keeps-automatically-restarting – Kevin Danikowski May 11 '21 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

ppostma1
  • 3,616
  • 1
  • 27
  • 28
  • 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 '16 at 08:25
  • Thanks, this worked. This is also where you find the uninstall button. – smcg Apr 29 '19 at 16:12
  • This worked for most: https://gist.github.com/vitorbritto/0555879fe4414d18569d but to be safe, try Step 7 before Step 6 – ppostma1 Apr 29 '19 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
Steven Lizarazo
  • 5,320
  • 2
  • 28
  • 25
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".

arnoldbird
  • 886
  • 1
  • 13
  • 30
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

Andreas Karz
  • 390
  • 3
  • 6
3

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

I found my answer on nixCraft.

J.W.F.
  • 641
  • 2
  • 12
  • 24
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.

Rajan
  • 625
  • 7
  • 19
Charles
  • 31
  • 1
2

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

portatlas
  • 657
  • 6
  • 12
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
Vikram Hosakote
  • 3,528
  • 12
  • 23
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
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
Oleksii Kyslytsyn
  • 2,458
  • 2
  • 27
  • 43
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

ahm
  • 107
  • 2
  • 9
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
ehacinom
  • 8,070
  • 7
  • 43
  • 65
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

Rajeev Jayaswal
  • 1,423
  • 1
  • 20
  • 22
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

0

sudo launchctl list | grep -i mysql

sudo launchctl remove xxx.xxx.mysqlxxx

This works for me!

-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.
kevnk
  • 18,733
  • 3
  • 28
  • 30