How to restart MySQL?

275,717

Solution 1

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

Start:

sudo /etc/init.d/mysql start

Stop:

sudo /etc/init.d/mysql stop

Restart / reload configs:

sudo /etc/init.d/mysql restart

Check run status:

sudo /etc/init.d/mysql status

Solution 2

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

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

 2. # service mysql restart

Solution 3

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.

Solution 4

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

Solution 5

use the following command to restart mysql

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

    #Linux
    $ /etc/init.d/mysqld restart

    or

    $ service mysqld restart

    or

    $ systemctl restart mysqld
Share:
275,717

Related videos on Youtube

David
Author by

David

Updated on September 18, 2022

Comments

  • David
    David over 1 year

    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.

  • David
    David about 13 years
    Hi I'm new to the command line and MySQL. Can you show me exactly what I need to type into the terminal?
  • David
    David about 13 years
    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
    David about 13 years
    I think shutdown stops and then automatically starts mysql. Is there a command to permanately stop mysql?
  • David
    David about 13 years
    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'
  • Pylsa
    Pylsa about 13 years
    @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.
  • Derek Downey
    Derek Downey about 13 years
    @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.
  • David
    David about 13 years
    @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?
  • Pylsa
    Pylsa about 13 years
    @David Did you try using it with sudo? Like sudo service mysql stop?
  • Xenoactive
    Xenoactive about 13 years
    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.
  • David
    David about 13 years
    @BloodPhilia. You suggestion worked. Thank you for the clarifications.
  • Cerin
    Cerin over 10 years
    Note that Redhat distros no longer have many of these scripts.
  • OverrockSTAR
    OverrockSTAR about 9 years
    when I am trying with this command, it is failing - I am logged on as root. sudo /usr/bin/mysql status ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
  • MA-Maddin
    MA-Maddin about 6 years
    On Debian as well. But the first command made all my localhosts not working. They would need to be replaced by 127.0.0.1. The latter one didn't have that issue.
  • MA-Maddin
    MA-Maddin about 6 years
    Using /etc/init.d/mysql made all my localhost in php not working. They would need to be replaced by 127.0.0.1. With service mysql there wasn't that issue. (Debian 8, Apache 2.4.10, MySQL 5.7.17, php 7.0)
  • greenlungus
    greenlungus over 4 years
    Please add some detail about why this should help. Non-explanatory answers are discouraged, which likely led to the downvote.
  • Jitendra
    Jitendra about 4 years
    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