mysql MySql Login Unable to connect to any of the specified MySQL hosts

【现象说明】

服务器在公网环境下,客户端远端访问其一切正常。

服务器移至内网环境下,客户端无法远端访问,可以本地访问。

日志中报:

          MySql Login Unable to connect to any of the specified MySQL hosts

【原因分析】

话说配置好的服务环境没有被改动过,奇葩了呗...

报这个错误的可能原因太多了~~~目测该原因也只是个stupid mistake导致~~~人没到现场,且客户网络不允许连外网,看不到一手资料;犯错越简单,越难定位。

网上找到的一些可能原因:

1. 检查防火墙端口放开(之前在公网环境下已经配置过了)

Open Control Panel from the Start menu.
Select Windows Firewall.
Select Advanced settings in the left column of the Windows Firewall window.
Select Inbound Rules in the left column of the Windows Firewall with Advanced Security window.
Select New Rule in the right column.
Select Port in the New Inbound Rule Wizard and then click Next.
Select which protocol this rule will apply to (TCP or UDP), select Specific local ports, type a port number (80), port numbers (80,81), or a range of port numbers (5000-5010) and then click Next.
Select Allow the connection and then click Next.
Select when this rule applies (check all of them for the port to always stay open) and then click Next.
Give this rule a name and then click Finish to add the new rule.

2. 检查防火墙IP白名单

I had a similar issue. My MySQL server was on a remote machine and by default it does not accept remote connections. I had to explictly add my machine's IP address to its list of accepted IPs.

3.检查.NET MYSQL Connector版本是否一致 (特别在ipv6环境下)(我应该没问题)

4.再检查一下远程访问权限(之前已配置过的)

Also: Make sure your user has the proper access privileges. Many hosting providers only enable access from localhost. You may have to request that they enable your user for remote access.

5. Connection string 使用Uid要改为User Id这种形式 (我没有这个问题)

如下public string strProvider = "Server=00.00.00.00;Database=someDatabase;Uid=someUser;Pwd=somePassword";

6.检查mysql是否把skip_networking设置成ON了  (客户端安装在服务器中可以正常访问,故不存在该问题)

If you log in on localhost, do SHOW VARIABLES LIKE 'skip_networking'

7. 路由器Rules检查

http://superuser.com/questions/582963/cant-connect-to-remote-mysql-server-but-works-with-localhost

检查服务所用端口是否在路由器一侧被限制


我的检查步骤:

A.检查服务mysqld.exe  端口

B. (1)Ping IP  ;      (2) Telnet IP PORT

C.检查防火墙和路由器设置(由于省中心管理的专有网络路由配置无法检查的)

D.检查skip_neworking和bing_address属性

E.检查host、账号、密码及对应权限  (1)SHOW GRANTS FOR root ; (2)select host,name password from user ;


【问题定位】

1. 原来代码中没捕获该异常,日志未记载,此乃stupid mistake 1。后来写了个小程序发客户测试才抓到了错误日志:

Exception Information
MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
   在 MySql.Data.MySqlClient.NativeDriver.Open()
   在 MySql.Data.MySqlClient.Driver.Open()
   在 MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   在 MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   在 MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
   在 MySql.Data.MySqlClient.MySqlPool.GetConnection()
   在 MySql.Data.MySqlClient.MySqlConnection.Open()
   在 agri.dbutility.SqlOpeMySql.Query(String SQLString)

然后要求关掉服务端防火墙~~~测试通过!!! 

2. 我以为防火墙配置妥当并经过多轮测试,客户反馈机子移到专用网络后没有人修改过配置,所以我对此深信不疑,此为stupid mistake 2。今后的网络程序,应该参考espace,网络连通性测试要在程序启动时候做(找最佳路由过程)。

3. 对于专有网络程序和机关单位的项目,不允许现场代码调试,无法远程定位,于客户处无法取得精确反馈。这就要做到:开发针对性运行环境侦测工具给客户;定位问题最好到现场(成本一开始就要考虑)。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值