【MySQL】8.0 执行授权语句报:ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that …

场景

在 ubuntu 上使用 Docker 安装了 Mysql 8 ,远程连接一直报错

Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
  Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
  Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.

先设置 远程登录权限,在进入 docker 容器后,使用命令行客户端连接MySQL ,执行如下语句:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
-- 或者
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';

都报如下错误:

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 'INDENTIFIED WITH mysql_native_password BY '123456'' at line 1

解决方案

根据提示,应是MYSQL 版本不同,语法不同所致。MySQL 8.0.x 应使用如下语句。

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

在这里插入图片描述


版权声明:本文为m0_47406832原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。