MySQL中grant all privileges on远程连接授权
记录MySQL远程连接所踩的坑
当你的帐号不允许从远程登陆,只能在localhost
连接时。这个时候只要在mysql服务器上,更改 mysql
数据库里的 user
表里的 host
项,从localhost"
改成%
即可实现用户远程登录
授权法
MySQL 5.0+版本
mysql -u root -p
-- 给root账户授权(root默认只有本机访问的权限,要通过其他机器访问,必须授权)
grant all privileges on *.* to root@'%' identified by 'root' with grant option;
-- 最后刷新数据库服务
flush privileges;
MySQL8.0版本不能按照grant all privileges on *.* to "root"@"%" identified by "xxxx";
去修改用户权限,会报错
MySQL 8.0+版本
#先创建远程用户,再授权
create user 'root'@'%' identified by 'root';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
注意授权后必须FLUSH PRIVILEGES;否则无法立即生效。