How to restart MySQL?
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
Related videos on Youtube
David
Updated on September 18, 2022Comments
-
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 followingsudo /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 about 13 yearsHi I'm new to the command line and MySQL. Can you show me exactly what I need to type into the terminal?
-
David about 13 yearsI 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 about 13 yearsI think shutdown stops and then automatically starts mysql. Is there a command to permanately stop mysql?
-
David about 13 yearsI 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 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. Usingservice
is just the "new way" of using startup scripts. To useservice
, just execute this on the terminal:service mysql stop
or start. -
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 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 about 13 years@David Did you try using it with sudo? Like
sudo service mysql stop
? -
Xenoactive about 13 yearsI 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 about 13 years@BloodPhilia. You suggestion worked. Thank you for the clarifications.
-
Cerin over 10 yearsNote that Redhat distros no longer have many of these scripts.
-
OverrockSTAR about 9 yearswhen 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 about 6 yearsOn Debian as well. But the first command made all my
localhost
s not working. They would need to be replaced by127.0.0.1
. The latter one didn't have that issue. -
MA-Maddin about 6 yearsUsing
/etc/init.d/mysql
made all mylocalhost
in php not working. They would need to be replaced by127.0.0.1
. Withservice mysql
there wasn't that issue. (Debian 8, Apache 2.4.10, MySQL 5.7.17, php 7.0) -
greenlungus over 4 yearsPlease add some detail about why this should help. Non-explanatory answers are discouraged, which likely led to the downvote.
-
Jitendra about 4 yearsThis 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
andsudo service mysql status
are helpful commands too