Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

Any suggestions? Thank you.

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.

Any suggestions?

share|improve this question
up vote 28 down vote accepted

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
share|improve this answer
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 '11 at 15:41
1  
@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. – BloodPhilia May 11 '11 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 '11 at 16:51
1  
@David Did you try using it with sudo? Like sudo service mysql stop? – BloodPhilia May 11 '11 at 17:34
    
@BloodPhilia. You suggestion worked. Thank you for the clarifications. – David May 11 '11 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
share|improve this answer

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.

share|improve this answer
    
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 '11 at 15:01
    
I think shutdown stops and then automatically starts mysql. Is there a command to permanately stop mysql? – David May 11 '11 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. – DTest May 11 '11 at 16:26

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".

share|improve this answer
    
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 '11 at 14:56
4  
kill -9 is a little rude, as it doesn't let a process clean up after itself. – gerryk May 11 '11 at 15:35
1  
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 '11 at 18:12

You must log in to answer this question.

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