I am running MySQL 5.1.54 and installed it on Ubuntu through the terminal using the command

sudo apt-get install mysql-server

I changed the my.cnf file and would like to stop and then start the database. I've tried the following

sudo /usr/bin/mysqld_safe stop

My question is how do I know that the database is stopped? When I run the above command, followed by

sudo mysql -uuser -ppassword

I can log right back into the database. Shouldn't it tell me that the database is not running?

EDIT: I've also tried

mysqladmin -uuser -ppassword shutdown

and then

ps aux | grep mysql

I get the following output

david    12093  0.0  0.0   6052  1276 pts/1    T    May10   0:00 nano /etc/mysql/my.cnf
root     12267  0.0  0.0   6396  1436 pts/1    T    May10   0:00 sudo nano /etc/mysql/my.cnf
root     12269  0.0  0.0   6052  1388 pts/1    T    May10   0:00 nano /etc/mysql/my.cnf
mysql    15371  0.3  0.1  55344  9088 ?        Ssl  10:53   0:00 /usr/sbin/mysqld
david    15512  0.0  0.0   5304   864 pts/1    R+   10:54   0:00 grep --color=auto mysql

Does the above output mean that MySQL has been shut down? If I run mysql -uuser -ppassword I can still log into MySQL.

6 Answers 6


You should really use the Sys-V init scripts located in /etc/init.d.


sudo /etc/init.d/mysql start


sudo /etc/init.d/mysql stop

Restart / reload configs:

sudo /etc/init.d/mysql restart

Check run status:

sudo /etc/init.d/mysql status
  • 1
    I tried that and I get the following error message `Rather than invoking init scripts through /etc/init.d, use the service(8) utility, e.g. service mysql status'
    – David
    May 11, 2011 at 15:41
  • 3
    @David This is the only right answer. service is just a small program that looks up the right init.d script for you. Even though it throws you the "error message", sudo /etc/init.d/mysql start/stop has still done its job. Using service is just the "new way" of using startup scripts. To use service, just execute this on the terminal: service mysql stop or start.
    – Pylsa
    May 11, 2011 at 16:10
  • @BloodPhilia, I tried service mysql stop and I get the following message: Rejected send message, 1 matched rules; type="method_call", sender=":1.72" (uid=1000 pid=17673 comm="stop mysql ") interface="com.ubuntu.Upstart0_6.Job" member="Stop" error name="(unset)" requested_reply=0 destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")). Any ideas?
    – David
    May 11, 2011 at 16:51
  • 2
    @David Did you try using it with sudo? Like sudo service mysql stop?
    – Pylsa
    May 11, 2011 at 17:34
  • 1
    @BloodPhilia. You suggestion worked. Thank you for the clarifications.
    – David
    May 11, 2011 at 18:37

In Ubuntu machines, you can restart the mysql using both commands :

 1. sudo /etc/init.d/mysql restart

 2. # service mysql restart
  • On Debian as well. But the first command made all my localhosts not working. They would need to be replaced by The latter one didn't have that issue.
    – MA-Maddin
    May 1, 2018 at 19:38

To shutdown mysql, run:

mysqladmin -uuser -ppassword shutdown

where user and password is that for a user with the proper SHUTDOWN privilege

To check that it has been shut down:

ps aux | grep mysql

If any processes (other than the 'grep' command) show up, it hasn't been shutdown.

  • I followed your instructions and I get an output. I've edited my question using your procedure. I can tell me if I'm on the right track?
    – David
    May 11, 2011 at 15:01
  • I think shutdown stops and then automatically starts mysql. Is there a command to permanately stop mysql?
    – David
    May 11, 2011 at 15:35
  • @David the automatic restarting is not a behaviour of mysqladmin shutdown . probably ubuntu's /etc/init.d/mysql behaviour? I'm not sure. I think @gerryk's answer is the correct one for your operating system. May 11, 2011 at 16:26
  • This is the right answer for shutting down the database. However, I had to perform an additional step sudo service mysql stop to make service inactive. ps aux | grep mysql and sudo service mysql status are helpful commands too
    – Jitendra
    Mar 15, 2020 at 7:22

the systemctl utility available by default in used to manage services in your linux box. it can be used to start, restart and stop services. There are other options you can use. checkout systemctl ?

systemctl stop mysql
systemctl start mysql
  • 1
    Please add some detail about why this should help. Non-explanatory answers are discouraged, which likely led to the downvote.
    – kdb
    Oct 27, 2019 at 20:17
  • This is helpful if you get command not found "/etc/init.d/mysql" and on "service mysql restart". My site was down and didn't have time to debug why those other answers didn't work so I tried this and it worked thanks! (on debian)
    – curtis
    Apr 17, 2023 at 8:17
  • Helpful, my server was full and mysql was in a broken state. Stopping and restarting fixed the problem (note that startup took some time, probably because of journaling).
    – 6infinity8
    Feb 25 at 12:01

You can use kill -9 "PID" command to do that, the MySQL Process ID (PID) you can get running ps -a or top commands. Then you can start it again by calling ./"main process".

  • Hi I'm new to the command line and MySQL. Can you show me exactly what I need to type into the terminal?
    – David
    May 11, 2011 at 14:56
  • 7
    kill -9 is a little rude, as it doesn't let a process clean up after itself.
    – gerryk
    May 11, 2011 at 15:35
  • 2
    I don't recommend doing this. Depending on what MySQL is doing at the time when it suddenly stops, you might restart to some unhappy databases.
    – Xenoactive
    May 11, 2011 at 18:12

use the following command to restart mysql

    # mysql start/stop/restart
    # MAC
    $ cd /path/mysql/bin
    $ mysql.server restart

    $ /etc/init.d/mysqld restart


    $ service mysqld restart


    $ systemctl restart mysqld

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .