1、首先进入mysql
mysql -u root -p
enter password:
回车就好
2、查询用户密码:
查询用户密码命令:mysql> select host,user,authentication_string from mysql.user;
host: 允许用户登录的ip‘位置'%表示可以远程;
user:当前数据库的用户名;
authentication_string: 用户密码(后面有提到此字段);
3、设置(或修改)root用户密码:
use mysql;(如果当前root用户authentication_string字段下有内容,先将其设置为空,否则直接进行二步骤。)
update user set authentication_string='' where user = 'root';
4、修改密码
ALTER user 'root'@'localhost' IDENTIFIED BY 'new password';
flush privileges
5、重连
重新输入mysql -u root -p
enter password:(输入你刚才设置的密码)
OK!完结!