gpt4 book ai didi

mysql - 检查连接时无法连接到任何指定的 MySQL 主机

转载 作者:行者123 更新时间:2023-11-29 04:21:21 25 4
gpt4 key购买 nike

我正在尝试通过 vb.net 连接到 Mysql 数据库但是我遇到了错误:

Unable to connect to any of the specified MySQL hosts

enter image description here这是代码:

    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 enter image description here

最佳答案

试试这个 ConnectionString:

 MysqlConn.ConnectionString = "Server=localhost;Database=My_Mysql_Database;Uid=root;Pwd=root;"

关于mysql - 检查连接时无法连接到任何指定的 MySQL 主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22962923/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com