mysql5.7 password initialization

1. Stop the mysql service
systemctl stop mysqld
2. The configuration file of the mysql service

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
skip-grant-tables #Add  this sentence, this When you log in to mysql, you do not need a password
symbolic-links=0

3. Start the mysql service

systemctl start mysqld

4. Login to mysql

mysql

5. Set a password

mysql> USE mysql ;

mysql> UPDATE user SET Password = password(‘new-password‘) WHERE User = ’root’ ;

mysql> flush privileges ;

mysql> quit

6. Comment out the skip-grant-tables in /etc/my.cnf and restore the configuration file as it is.

7. Stop the mysql service
systemctl stop mysqld

8. Start the mysql service

systemctl start mysqld

9. Use the password to log in to mysql

[root@sample ~]# mysql -u root -p enter password

Guess you like

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