检查连接时无法连接到任何指定的 MySQL 主机
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22962923/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to connect to any of the specified MySQL hosts when checking connection
提问by Ahmed Faizan
I am trying to connect to Mysql database through vb.net However I run into the error:
我正在尝试通过 vb.net 连接到 Mysql 数据库但是我遇到了错误:
Unable to connect to any of the specified MySQL hosts
Here is the code:
这是代码:
Imports MySql.Data.MySqlClient
Public Class DBProject_1
Dim MysqlConn As MySqlConnection
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MysqlConn = New MySqlConnection
MysqlConn.ConnectionString = "server=localhost;userid=root;password=root;database=My_Mysql_Database"
Try
MysqlConn.Open()
MessageBox.Show("Connection Successful")
MysqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
End Sub
End Class
I have even tried to use
我什至尝试使用
MysqlConn.ConnectionString = "server=**127.0.0.1**;userid=root;password=root;database=My_Mysql_Database"
This may be the reason:
When I test connection of the Mysql database in Mysql Workbench the test fails.
The error is Failed to Connect to Mysql at 127.0.0.1:3306 with user root
这可能是原因:当我在 Mysql Workbench 中测试 Mysql 数据库的连接时,测试失败。错误是Failed to Connect to Mysql at 127.0.0.1:3306 with user root
回答by ?s??? ????
Try with this ConnectionString
:
试试这个ConnectionString
:
MysqlConn.ConnectionString = "Server=localhost;Database=My_Mysql_Database;Uid=root;Pwd=root;"
回答by Mike Lischke
The "Can't connect to MySQL server" error usually is the result of not being able to reach the server, e.g. if it is not running or it is on a remote machine but firewalls block access. See also the video I added to the MySQL channelfor how to set up connections.
“无法连接到 MySQL 服务器”错误通常是无法访问服务器的结果,例如,如果它没有运行或者它在远程机器上但防火墙阻止访问。另请参阅我添加到 MySQL 频道的视频,了解如何设置连接。
回答by Awesh Vishwakarma
Please check that MySql Service is running by typing "services.msc" in the "run". I hope it will help you!
请通过在“运行”中键入“services.msc”来检查 MySql 服务是否正在运行。我希望它会帮助你!
回答by Awesh Vishwakarma
I have the same problem. But I was a server, in a domain, and now the server is outside the domain.
我也有同样的问题。但我是一个服务器,在域中,现在服务器在域外。
I try to change the rulesin firewall of the server (where there is MySql server). So go to inbound rules, and search the 2 Mysql rules.
我尝试更改服务器的防火墙规则(有 MySql 服务器的地方)。所以转到入站规则,并搜索2个Mysql规则。
Open them and search th Advanced item. Then check Domain, or/and Private, or/and Public
打开它们并搜索高级项目。然后检查域,或/和私人,或/和公共
(for me, Domain was the only cheked option, not good for me because I 'm now outside the domain).
(对我来说,域是唯一的选择,对我不利,因为我现在在域之外)。
Hope it helps ! Cheers :)
希望能帮助到你 !干杯:)