1、登录数据库
mysql -u root -p
然后按回车键输入密码。
2、查看并进入mysql数据库
show databases;
use mysql;
3、查看mysql的用户
select host,user,authentication_string from user;
注意: mysql5.7以后的密码字段是authentication_string
4、修改用户的远程登录权限并刷新
update user set host = '%' where user = 'root';
flush privileges;
注意: 默认的localhost仅能访问本地,而%表示任何客户端都能登录到mysql服务器
5、修改登录密码并刷新
update mysql.user set authentication_string=password('新密码') where user='用户名' and Host ='localhost';
flush privileges;