升级了MySQL版本,yum安装了8.0的版本后开启远程连接(8.0之前的方法
use mysql
;
GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘您的密码’ WITH GRANT OPTION;
FLUSH PRIVILEGES;
)
出现了
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@abc-123’ WITH GRANT OPTION’ at line 1
的错误。百度了一下找到了解决的办法。
- 连接到MySQL
mysql -uroot -p #输入密码 #切换数据库 use `mysql`; #查询用户和对应的主机信息 select user,host from user; mysql> select user,host from user; +------------------+-----------+ | user | host | +------------------+-----------+ | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +------------------+-----------+ 4 rows in set (0.00 sec) #执行修改sql,需要修改 root 对应的 host 为 %。 update user set host = '%' where user = 'root'; #刷新 flush privileges; #再次查询用户和对应的主机信息 select user,host from user; mysql> select user,host from user; +------------------+-----------+ | user | host | +------------------+-----------+ | root | % | | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | +------------------+-----------+ 4 rows in set (0.00 sec) #修改完成后还需要授权 grant all privileges on *.* to 'root'@'%';
- 开始防火墙的3306端口,如果是云服务器记得开放安全组。不需要重启MySQL服务,直接用navicat连接就可以了。