Modify the root password of mysql under centos

After mysql is installed, the mysql command line login to mysql prompts the following error:

Access denied for user 'root'@'localhost' (using password:YES)

The possible reason is that you don't know the root password.

You can use the following methods to change the root user password:

1. Modify the startup parameters of the service

south you /usr/lib/systemd/system/mysqld.service

Add the skip-grant-tables parameter to the startup command

ExecStart=/usr/bin/mysqld_safe --skip-grant-tables

 

2. Execute daemon-reload

sudo systemctl daemon-reload

 

3. Restart the mysql service

sudo systemctl restart mysqld

 

4. Use the root user to log in to mysql

mysql -uroot

5. Modify the root password

use mysql;

update user set password=PASSWORD("123456") where user='root';

 

6. Refresh permissions

After changing the password, refresh the permissions

flush privileges;

7. Remove the skip-grant-tables of the startup parameters of the service and restart

The startup command is modified to:

ExecStart=/usr/bin/mysqld_safe

After modification, execute

sudo systemctl daemon-reload

sudo systemctl restart mysqld

After restarting, use root/123456 to log in.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326001012&siteId=291194637