场景
在 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'@'%';