Windows连接虚拟机中的mysql5失败

Windows连接虚拟机中的mysql5失败

虚拟机版本为centos6.8,数据库版本为mysql5.6,系统版本为window11。在虚拟机上安装好mysql,并且配置好权限,虚拟机登录正常之后。在windows11上使用工具dbeaver连接mysql失败,报错 CommunicationsException: 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.

Mysql连接失败无非以下几个问题:

  • Mysql连通性;
  • Mysql权限;
  • 虚拟机与windows连接性;
  • 防火墙;
  1. Mysql连通性;

在虚拟机上使用一下命令测试mysql连通性

bash 复制代码
$ mysql -h192.168.177.11 -uroot -pzhou59420 -P3306

如果使用指定ip无法登录,尝试编辑mysql配置文件,修改登录指定ip

bash 复制代码
$ vi /etc./my.conf
bind-address=192.168.177.11
  1. Mysql权限;

进入mysql客户端,执行以下命令查看mysql登录权限

sql 复制代码
mysql>select User, Host, Password from mysql.user;

查看除localhost与127.0.0.1之外是否有指定ip连接方式,如无,可修改为指定ip

  1. 虚拟机与windows连接性;

在windows上win+r呼出运行窗口,键入cmd然后执行ping 192.168.177.11查看虚拟机ip是否可访问

  1. 防火墙

在mysql客户端查看mysql端口

sql 复制代码
mysql> show variables lile '%port%';

在windows上win+r呼出运行窗口,键入cmd然后执行telnet 192.168.177.11 3306查看端口是否可访问

如果不可访问,在虚拟机检查3306端口是否开放

bash 复制代码
$ service iptables status

如果未开放,编辑空值文件,新增防火墙开放端口/etc/sysconfig/iptables

bash 复制代码
$ vi /etc/sysconfig/iptables


然后重启防火墙

bash 复制代码
$ service iptables restart

重复cmd检查3306端口状态,如已开启再次尝试dbeaver连接.

相关推荐
情 九26 分钟前
Dify 本地环境搭建教程:macOS / Windows
windows·macos
Dxy12393102161 小时前
MySQL分库分表如何选择ID
mysql
imDwAaY1 小时前
SQL 查询突然变慢了?一篇讲清慢 SQL 排查思路
后端·mysql
花间相见1 小时前
【计算基础|MySQL03】【上手】多表查询与聚合
数据库·mysql
冰暮流星2 小时前
mysql索引失效的情形
数据库·笔记·sql·mysql
Escalating_xu2 小时前
【Linux 网络编程】Windows 客户端访问 Linux:用 Winsock 跑通 UDP 回显
linux·网络·windows
Pniubi2 小时前
三种count
mysql
biaov3 小时前
使用 Windows 自带的 VHDX + BitLocker 加密学习资料
windows·加密
三块一毛四3 小时前
set_global_opts / set_series_opts 参数
windows
ynchyong3 小时前
创建MySQL只读账号
android·数据库·mysql