写在前面
MySQL开启远程访问权限,通常命令如下:
此处是为IP为192.168.0.***,用户名为root的用户,开启访问test1数据库的所有权限
rant all privileges on test1.* to "root"@"192.168.0.***" identified by "root" with grant option;
报错
原因
版本问题,MySQL8.0以上版本并不适用这种命令来开启远程访问权限
解决方法
依次执行下面命令
create user 'root'@'192.168.0.***' identified by 'colin'; # root为用户名,192.168.0.***需要访问的机器的IP,colin是密码
grant all on test1.* to 'root'@'192.168.0.***'; # root为用户名,192.168.0.***需要访问的机器的IP
alter user 'root'@'192.168.0.***' identified with mysql_native_password by 'colin'; # root为用户名,192.168.0.***需要访问的机器的IP,colin是密码
flush privileges; # 刷新权限,让设置生效
效果