检查连接时无法连接到任何指定的MySQL主机 [英] Unable to connect to any of the specified MySQL hosts when checking connection
本文介绍了检查连接时无法连接到任何指定的MySQL主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过vb.net连接到Mysql数据库 但是我遇到了错误:
I am trying to connect to Mysql database through vb.net However I run into the error:
Unable to connect to any of the specified MySQL hosts
这是代码:
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
我什至尝试使用
MysqlConn.ConnectionString = "server=**127.0.0.1**;userid=root;password=root;database=My_Mysql_Database"
这可能是原因:
当我在Mysql Workbench中测试Mysql数据库的连接时,测试失败.
错误是Failed to Connect to Mysql at 127.0.0.1:3306 with user root
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
推荐答案
尝试使用此ConnectionString
:
MysqlConn.ConnectionString = "Server=localhost;Database=My_Mysql_Database;Uid=root;Pwd=root;"
这篇关于检查连接时无法连接到任何指定的MySQL主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文