Can't start/stop mysql service

Taking over a Debian Etch web server with MySQL running.

I usually start, stop and restart msyql using:

/etc/init.d/mysql restart

For some reason on this set up I get the following:

:~# /etc/init.d/mysql stop

Stopping MySQL database server: mysqld failed!

The mysql process is running fine:

:~# ps aux | grep mysql 
root      2045  0.0  0.1   2676  1332 ?        S    Jun25   0:00 /bin/sh /usr/bin/mysqld_safe
mysql     2082  0.6 10.7 752544 111188 ?       Sl   Jun25  18:49 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --port=3306 --socket=/var/run/mysqld/mysqld.sock
root      2083  0.0  0.0   1568   504 ?        S    Jun25   0:00 logger -p daemon.err -t mysqld_safe -i -t mysqld
root     11063  0.0  0.0   2856   716 pts/0    S+   17:29   0:00 grep mysql

I'm sure there are some really easy way to do it but I want to understand what is going on as well. Why is the typical way not working for me?

EDIT UPDATE as an update:

JBRLSVR001:/var/log/mysql# mysqladmin shutdown
JBRLSVR001:/var/log/mysql# dpkg --list mysql\*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed 
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name                                         Version                                      Description
 +++-============================================-============================================-========================================================================================================
un  mysql-client                                 <none>                                       (no description available)
un  mysql-client-4.1                             <none>                                       (no description available)
ii  mysql-client-5.0                             5.0.32-7etch8                                mysql database client binaries
ii  mysql-common                                 5.0.32-7etch8                                mysql database common files (e.g. /etc/mysql /my.cnf)
un  mysql-common-4.1                             <none>                                       (no description available)
ii  mysql-server                                 5.0.32-7etch8                                mysql database server (meta package depending on the latest version)
un  mysql-server-4.1                             <none>                                       (no description available)
ii  mysql-server-5.0                             5.0.32-7etch8                                mysql database server binaries

mysqladmin shutdown does work but i'm still curious why the /etc/init.d/mysql commands aren't working.


Solution 1:

mysqladmin shutdown

should work to shutdown the server.

I see two likely possibilities:

  1. MySQL has a problem and is refusing to shut down for some reason.
  2. The previous admin did something strange. Either modified the init.d script or didn't bother using the Debian packages at all to install MySQL.

What does dpkg --list mysql\* say?

What does /var/log/mysql.err say? Or the other mysql logs?

EDIT:

So mysqladmin shutdown worked?

According to that, the mysql-server package is installed (mysql-server-5.0; the mysql-server package is probably just a stub). So they may have installed over it? Running debsums mysql-server-5.0 might tell you more. dpkg --listfiles mysql-server-5.0 could help, too...

What's actually in /etc/init.d/mysql? I haven't checked that specific version of the package, but it should try to use mysqladmin shutdown ... Maybe you're lucky and they only broke that...

Solution 2:

Why this is happening

This is a common problem if you do a mysql import and overwrite the mysql database itself, such as when you might be restoring from a mysqldump -A backup.

This is a good thing: you probably want to back up all your mysql users, permissions, etc -- but it can wreak havoc with things like the debian-sys-maint user used to cleanly shutdown mysql.

Although this new database will possibly change both the root password and the debian-sys-maint password, of course it won't automatically change the expected debian-sys-maint password in /etc/mysql/debian.cnf. In fact, unless you also backed up that file, you probably don't even know what that password is anymore!

Resetting the mysql root password (optional)

First things first. If the mysql root password was different between old and new servers, you can use mysqladmin to fix it:

mysql -p -u root password 'newpassword'

However, when you apt-get installed mysql-server, it probably prompted you for the new mysql root password and you probably used the same one that you were using from before.

Fix the debian sys maint password.

So now look up the debian sys maint password that debian created for you when you installed it on the new server. (You need sudo because this should be a highly protected file.)

sudo cat /etc/mysql/debian.cnf

Now, log in to mysql using the root password you set above:

mysql -p -u root   # use your new password when prompted

Reset the password for the debian-sys-maint user and don't forget to flush privileges:

>  SET PASSWORD FOR 'debian-sys-maint'@'localhost' = PASSWORD('samepassword');
>  FLUSH PRIVILEGES;
>  QUIT

Test to be sure it works:

sudo /etc/init.d/mysql restart

Quick tip

If you ever need to reset the root password for the server without having to bring down the server, this user account has the authority to do it -- just cat the debian.cnf file and log in with that user. N.B. Protect this user account just like root.

Solution 3:

pkill mysql

will definitely work

Solution 4:

2 more hints:

sh -x /etc/init.d/mysql restart

This will show you the commands executed by the init script.

install the package debsums, and you can test which packages were modified (verify is also available for RPM, but IMHO works better).