宿主机外访问:

(base) root@gpu-63:/data1/mysql# telnet 214.2.15.1 3308
Trying 214.2.15.1...
Connected to 214.2.15.1.
Escape character is '^]'.
CHost '214.2.15.1' is not allowed to connect to this MySQL serverConnection closed by foreign host.

进入容器访问

(base) root@gpu-63:/data1/mysql1022# docker exec -it mysql1022 /bin/bash

bash-4.4# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
 

bash-4.4# /usr/bin/mysql -u root -p                     
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
 

这个错误表明客户端无法通过 /var/run/mysqld/mysqld.sock 连接到 MySQL 服务。根据日志,MySQL 的 Unix 套接字位于 /var/lib/mysql/mysql.sock,但客户端默认尝试通过 /var/run/mysqld/mysqld.sock 进行连接

指定正确的套接字路径

你可以使用 --socket 选项指定正确的套接字文件路径:

/usr/bin/mysql -u root -p --socket=/var/lib/mysql/mysql.sock

查看root访问只能是localhost

修改访问源

update  mysql.user set host='%' where user='root';

外层测试:

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐