Maison > base de données > tutoriel mysql > le corps du texte

Reprendre le contrôle de l'utilisateur root dans MySQL

PHPz
Libérer: 2024-08-26 06:30:31
original
263 Les gens l'ont consulté

Retake control of the root user in MySQL

When you installed MySQL for the first time, you can't login with a no-password.
You should add the following line in my.cnf to login without a password.

skip-grant-tables
Copier après la connexion
Copier après la connexion

It has a huge security risk, so that you should set a password to prevent external, illegal access.

How to Retake Control of the Root User in MySQL

Step1: Connect to MySQL

mysql
Copier après la connexion

Step2: Using the main database

use mysql;
Copier après la connexion

Step3: Redefine user root password

UPDATE user SET `authentication_string` = PASSWORD('myNuevoPassword') WHERE `User` = 'root';
Copier après la connexion

Caution
If you can't execute the command, you should check authentication_string column of mysql.user table.

SELECT User, authentication_string  FROM mysql.user\G
*************************** 1. row ***************************
                 User: mysql.infoschema
authentication_string: $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED
*************************** 2. row ***************************
                 User: mysql.session
authentication_string: $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED
*************************** 3. row ***************************
                 User: mysql.sys
authentication_string: $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED
*************************** 4. row ***************************
                 User: root
W&2-*D:1FsLlMJEFsvaZNpaAlnJDEyTNo2QO7Eu7P0rhe10psBsC
4 rows in set (0.00 sec)
Copier après la connexion

And you execute the following command.

UPDATE user SET `authentication_string` = 'myNuevoPassword' WHERE `User` = 'root';
Copier après la connexion

Step4: Show mysql.user table if you could change root password

SELECT User, authentication_string  FROM mysql.user\G
*************************** 1. row ***************************
                 User: mysql.infoschema
authentication_string: $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED
*************************** 2. row ***************************
                 User: mysql.session
authentication_string: $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED
*************************** 3. row ***************************
                 User: mysql.sys
authentication_string: $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED
*************************** 4. row ***************************
                 User: root
authentication_string: ZAQ$2wsx2408
4 rows in set (0.00 sec)
Copier après la connexion

Step5: Erase line from my.cnf

skip-grant-tables
Copier après la connexion
Copier après la connexion

Step6: Restart MySQL service

sudo systemctl restart mysqld
Copier après la connexion

Step7: Connect to mysql with password

mysql -u root -p
Enter password: [new password]

mysql> 
Copier après la connexion

When you need to do this action, please use carefully!

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

source:dev.to
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!