mysql修改密码

mysql修改密码的方式常见的有以下四种:

1. 已知密码的情况下:

1.1 mysqladmin修改

mysqladmin -uroot -p1204 password 1234

1.2 set password

set password for [email protected] = password('2345');

1.3 update user  (mysql5.7以后是setauthentication_string字段,之前是password)

mysql> use mysql; 
mysql> update user set authentication_string=password('123') where user='root' and host='localhost'; 
mysql> flush privileges; 
mysql> exit; 

mysql修改密码

mysql修改密码

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;