Accueil > Programmation > mysql - mariadb > changer le mot de passe root du mysql/mariadb
changer le mot de passe root du mysql/mariadb
Publié le 21 décembre 2018, dernière mise-à-jour le 10 septembre 2024, > 15 visites, >> 9056 visites totales.
mettre un nouveau mot de passe : solution 2024/bookworm
Parfois, il est impossible de changer correctement le mot de passe comme indiqué en dessous ; une solution : nettoyer la table user
service mysql stop ; service mysqld stop ; /etc/init.d/mysql stop ; /etc/init.d/mysqld stop
service mysql start ; service mysqld start ; /etc/init.d/mysql start ; /etc/init.d/mysqld start
mysql -u root
use mysql;
select * from user;
truncate table user;
flush privileges;
grant all privileges on *.* to root@localhost identified by 'Motdepasse' with grant option;
flush privileges;
quit;
service mysql stop ; service mysqld stop ; /etc/init.d/mysql stop ; /etc/init.d/mysqld stop
service mysql start ; service mysqld start ; /etc/init.d/mysql start ; /etc/init.d/mysqld start
mettre un nouveau mot de passe : solution 2023/bullseye
mettre un nouveau mot de passe
Arrêter le serveur mysql ( erreurs normales )
Démarrer le serveur mysql sans mot de passe :
on se connecte à mysql :
Dans mysql , on va 1)choisir la base de donnée mysql, 2)mettre à jour le mot de passe root puis 3)on intègre le mot de passe à mysql ; 4) on sort
on redémarre
test : mot de passe changé et accepté
mysql -u root
doit donner
ERROR 1045 (28000) : Access denied for user ’root’@’localhost’ (using password : NO)
mot de passe changé mais non accepté
Parfois le mot de passe est bon mais tout est comme si le mot de passe n’était pas accepté :
solution rapide : sur debian l’option 1 marche,donc
https://stackoverflow.com/questions/39281594/error-1698-28000-access-denied-for-user-rootlocalhost :
Some systems like Ubuntu, mysql is using by default the UNIX auth_socket plugin.
Basically means that : db_users using it, will be "auth" by the system user credentias. You can see if your root user is set up like this by doing the following :
recherche de solution
mysql -u root
mysql>
USE mysql;
SELECT User, Host, plugin FROM mysql.user;
User | plugin |
root | unix_socket ( ou auth_socket ) |
mysql.sys | mysql_native_password |
debian-sys-maint | mysql_native_password |
As you can see in the query, the root user is using the auth_socket plugin
There are 2 ways to solve this :
You can set the root user to use the mysql_native_password plugin
You can create a new db_user with you system_user (recommended)
Option 1 :
Option 2 : (replace YOUR_SYSTEM_USER with the username you have)
Remember that if you use option #2 you’ll have to connect to mysql as your system username (mysql -u YOUR_SYSTEM_USER)
Note : On some systems (e.g., Debian stretch) ’auth_socket’ plugin is called ’unix_socket’, so the corresponding SQL command should be : UPDATE user SET plugin='unix_socket' WHERE User='YOUR_SYSTEM_USER';
voir aussi /usr/bin/mysql_secure_installation