MYSQL8 modify root password
Step 1: modify the configuration file to log in to mysql without password
1. Enter the file: vi /etc/my.cnf
2. Press the i key to indicate that it can be edited; add skip-grant-tables; press the esc key, enter: wq to save and exit
3. Restart mysql: sudo service mysqld restart
The second step is to log in to mysql without password
1. Login: mysql -u root -p
2. Prompt to enter the password and press Enter to enter
3. Enter the database, enter: use mysql;
4. View root user information: select host, user, authentication_string, plugin from user;
5. Update the root user information and set the password to an empty string: update user set authentication_string='' where user='root';
The third step is to exit mysql; comment out the skip-grant-tables at the end of the /etc/my.cnf file; restart: sudo service mysqld restart
Step 4: Set a password
1. Restart a client;
2. Log in to mysql (you don't need to enter the password at this time, because the password has been set to an empty string above);
3. Modify root user password: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your password';
4. After exiting mysql, you can log in with the password