Mysql Changing the administrator root password is a very common problem. There are many tutorials on the Internet. However, the new version of MYSQL5.7 can use the previous tutorials. After some exploration, the editor found a way to modify it. Here Share it with everyone.
Version update, the password field in the original user has been changed to authentication_string
Version update. Because of this, many online tutorials are no longer applicable, and even the official website documents cannot be operated smoothly.
If MySQL is running, kill it first:
killall -TERM mysqld。
Run
mysqld_safe --skip-grant-tables &
If you don’t want to be connected remotely at this time:
mysqld_safe --skip-grant-tables --skip-networking &
Use mysql to connect to the server
Change password:
update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';
*One thing to note in particular is that there is no Password field in the user table under the new version of mysql database
Instead, the encrypted user The password is stored in the authentication_string field
mysql> flush privileges; mysql> quit;
modified. Restart
killall -TERM mysqld。 mysqld_safe &
Then mysql can be connected
But the operation seems to be incomplete at this time, and you need to alter user...
alter user 'root'@'localhost' identified by '123';
The Internet article said that Jiang Zi can also do it:
set password for 'root'@'localhost'=password('123'); cp mysql.server /etc/init.d/mysql chmod +x /etc/init.d/mysql chkconfig --add mysql
The above is the detailed content of How to change the root password sharing in Mysql5.7. For more information, please follow other related articles on the PHP Chinese website!