Changer le mot de passe mysql

De Le Wiki du Forum-Debian.fr
Aller à la navigation Aller à la recherche

Changer le mot de passe Mysql

Il peut arriver d'avoir à changer le mot de passe "root" de Mysql. Voici la méthode:

Stoppez MySql

# /etc/init.d/mysql stop

Démarrez ensuite MySql avec les options suivantes: (Permet de démarrer sans prendre en compte les droits et sans écouter le réseau) L'option --skip-networking est très importante du point de vue de la sécurité, elle permet d'éviter à un petit malin de prendre le controle de MySql - sans mot de passe - pendant votre petite manip...)

# /usr/sbin/mysqld --skip-grant-tables --skip-networking &

Dans une autre console, accédez à MySql (sans mot de passe...)

# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.49-3 (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> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> SET PASSWORD FOR root@'localhost' = PASSWORD('votre_nouveau_mot_de_passe');
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

Redémarrez MySql en mode "normal":

# service mysql restart

Faites un test avec le nouveau mot de passe:

# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 88
Server version: 5.1.49-3 (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> exit
Bye

Voilà!

Sources

Lol 22 janvier 2012 à 06:38 (CET)