As a front-end, I am very weak in database. Although I have done back-end development for nearly a year before, I have been doing pure front-end for nearly three years. The version of mysql has also been upgraded from 5.6 to version 8. It’s almost a clean SLATE for me. Learning Mysql articles believe that there are a lot of online, so do not do learning record, just record in the process of learning Mysql8 encountered problems and corresponding solutions.
Today, I just downloaded Mysql from the official website to the local, and followed the tutorial to install and execute, but I encountered problems when logging in…
During initialization, an initial password was given, but I could not log in with this initial password…
Because the initial password given has a lot of special characters, basic can not remember, in order to later login do not need to find the password every time, but also to solve the problem that I can not log in, therefore, encountered the first question of learning Mysql – how to change the password of root account when you forget the password?
Through the online information, I also successfully changed the password of root and logged in Mysql. The specific process is recorded as follows:
- Skip password login
To change the password of user root, log in to the Mysql console first, but there is no password for user root, so you must start Mysql without checking the password. Open a cli window as an administrator and run the following command:
mysqld --console --skip-grant-tables --shared-memory
Copy the code
If the information shows that Mysql is running, the system starts successfully.
- Log on to the Mysql
Since Mysql is started without checking the password, you can connect to Mysql directly. Open another command line window as an administrator:
mysql
Copy the code
If the preceding information is displayed, the login is successful.
- None example Set the password of user root to null
update mysql.user set authentication_string="" where user="root";
flush privileges;
Copy the code
- Change the password
alter user 'root'@'localhost' identified with mysql_native_password by '123456';
flush privileges;
Copy the code
After successful execution, Query OK is displayed, and 0 rows affected indicates that the password has been successfully changed.
- Log in to Mysql using the password
Mysql > Mysqlnet start Mysql; Mysql > Mysqlnet start Mysql;
mysql -h localhost -u root -p
Copy the code