Mysql 5.7 root password setting after installation

https://www.yanning.wang/archives/379.html

1. Modify /etc/my.cnf and add a line under the [mysqld] section: skip-grant-tables=1

This line configures mysqld to start without password 2. Restart the

mysqld service: systemctl restart mysqld

3. Log in to mysql using the root user: mysql -u root

4. Switch to the mysql database and update the user table:

update user set authentication_string = password('root'), password_expired = ' N', password_last_changed = now() where user = 'root';
In previous versions, the field name of the password field was password, and in version 5.7, it was changed to authentication_string

5. Exit mysql, edit the /etc/my.cnf file, and delete skip -grant-tables=1

content


There are records, you can view them through the cat command and find the password keyword

After finding the password, log in with the initial password on the local machine, and (only) change the password of the root user to root through the alter user 'root'@'localhost' identified by 'root' command, then exit, and use the root user again Just log in with the password you just set.

Guess you like

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