mysql修改密码的方式常见的有以下四种:
1. 已知密码的情况下:
1.1 mysqladmin修改
mysqladmin -uroot -p1204 password 1234
1.2 set password
set password for root@localhost = password('2345');
1.3 update user (mysql5.7以后是setauthentication_string字段,之前是password)
mysql> use mysql;
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> update user set authentication_string=password('123') where user='root' and host='localhost';
mysql> flush privileges;
mysql> exit;
ubuntu18需要在flush privileges前加
update user set plugin="mysql_native_password";
2.忘记密码的情况下:
sudo /etc/init.d/mysql stop
sudo mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
mysql> use mysql;
mysql> update user set authentication_string=password('123') where user='root' and host='localhost';
mysql> flush privileges;
mysql> exit;