mysql access denied

Access denied for user debian-sys-maint

Que faire quand on ne peut plus redémarrer mysql via le script init.d

mysql debian sys maint, debian sys maint mysql, access denied for user debian sys maint localhost, mysql access denied for user, mysql database server mysqld failed, mysql access denied, acces denied, stopping mysql database server mysqld failed, pb droit mysql debian, access denied for user debian sys maint, stopping mysql database server mysqld, documentation sur exim linux, mysql, mot de passe, droit mysql

Date de publication : 2012-02-06 09:07:31

Pour la petite histoire

Ce matin, j'ai eu une bonne surprise sur ma debian. En restaurant une base de données sur MySQL mon courant s'est coupé. Du coup, redémarrage du PC et réinstallation de la base de données car mysql refusait de démarrer :

[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

Pour résoudre ce problème j'ai dut réinstaller la base de données mysql.

Réinstallation de la base mysql

Rien de plus facile avec la ligne de commande :

root@home:~# mysql_install_db
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h 127.0.1.1 password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/scripts/mysqlbug script!

Ensuite, j'ai redémarré mysql avec la ligne de commande habituelle :

root@home:~# /etc/init.d/mysql restart
* Stopping MySQL database server mysqld [fail]
* Starting MySQL database server mysqld [ OK ]
/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'debian-sys-maint'@'localhost' (using password: YES)'

Et là c'est le drame ! Pour corriger cela il faut trouver le mot de passe du user debian-sys-maint qui se trouve dans le fichier /etc/mysql/debian.cnf. :

root@home:~# cat /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = motdepasse-debian-sys-maint
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = motdepasse-debian-sys-maint
socket = /var/run/mysqld/mysqld.sock
basedir = /usr

Une fois le mot de passe trouvé, il faut modifier les droits mysql pour ce user en se connectant à mysql. Comme je viens de réinitialiser la base de données mysql, mon mot de passe root est vide (je tape entrée), le cas échéant : utilisez votre mot de passe root mysql.

root@home:~# mysql mysql -p
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.49-3-log (Debian)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY 'motdepasse-debian-sys-maint';
Query OK, 0 rows affected (0.00 sec)

J'ai ensuite modifier mon mot de passe root mysql (toujours parce que j'ai réinstallé la base mysql). Et tout est enfin rentré dans l'ordre :

root@home:~# /etc/init.d/mysql restart
Stopping MySQL database server: mysqld.
Starting MySQL database server: mysqld ..
Checking for corrupt, not cleanly closed and upgrade needing tables..

Bonne semaine à vous ;)

Image : Psychostretch

 
 

b1n@sp1n