**mysql_5.6版本授权用户远程登录**
mysql>grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
**mysql8.0授权远程登录**
之前一直用mysql5.6 远程授权登录,后来换mysql8.0原来的授权方式报错
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'root' with grant option' at line 1
**正确的方法需要先创建用户和密码**
mysql> create user 'test'@'%' identified by 'Test123';
**允许用户操作权限 ALL代表所有权限**
mysql> GRANT ALL PRIVILEGES ON *.* TO 'test'@'%';
**允许用户远程登录权限(如不需要远程登录可以忽略不加)**
mysql> ALTER USER 'test'@'%' IDENTIFIED WITH mysql_native_password BY 'Test123';
**刷新数据库**
mysql> FLUSH PRIVILEGES;
如果用Navicat连接的回报不支持caching_sha2_password验证方式的错误
将远程访问用户的验证方式改为: msyql_native_password
ALTER USER 'username'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
刷新数据库
mysql> FLUSH PRIVILEGES;