1.登录mysql命令:mysql -uroot -p (回车输入密码)
2.查询用户表和主机权限命令:
use mysql
select user, host from mysql.user;
备注:这里的%代表的是任意机器都能通过root来远程链接到服务器,我们可以直接删除掉这个用户重新定义用户和密码。
3.删除root这个远程访问用户,
delete from mysql.user where user = 'root' and host = '%';
4.更新权限命令:
flush privileges;
5.重新查询用户表和主机权限如下:
6.重新创建远程操作账户,进行远程访问的授权并更新权限,依次执行以下代码:
create user 'root'@'%' identified with mysql_native_password by '123456';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
或者
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION ;
FLUSH PRIVILEGES;
备注:修改本地mysql密码或者远程访问密码另一个方法如下
用UPDATE直接编辑user表
mysql -u root -p
mysql> use mysql;
mysql> UPDATE user SET password = PASSWORD('新密码') WHERE user = 'root';
mysql> FLUSH PRIVILEGES;
或 分别设置本地和远程登录密码,密码可不同
mysql> update mysql.user set password=password('123') where user='root' and host='localhost'; 本地
mysql> update mysql.user set password=password('123') where user='root' and host='%'; 远程
mysql> update mysql.user set password=password('123') where user='root' and host='BI-162';
mysql> flush privileges;