gpt4 book ai didi

mysql - Excel VBA连接远程MySQL数据库

转载 作者:行者123 更新时间:2023-11-29 13:31:05 29 4
gpt4 key购买 nike

我正在使用 OBDC 连接器来使用 VBA 连接到我的 MySQL 数据库。它当前在本地网络服务器 (localhost) 上运行,但可以通过我的 PC 的 IP 地址从网络上的其他 PC 进行访问。

在我的连接函数中,我有 localhost作为位置,但当我将其更改为我的 IP 地址时,我得到一个

[MySQL][ODBC 5.2 Driver] (my computer name) is not allowed to connect to this MySQL server

错误。

我认为这是一个安全问题。有办法解决这个问题吗?

这是我的连接函数:

Public Function OpenConnection() As ADODB.connection
//This function requires the "Microsoft ActiveX Data Objects" Library (Choose v2.8 from references for compatibility across Office versions)

Dim source As String, location As String, user As String, password As String
source = "MySQL"
location = "192.168.1.60"
user = "root"
password = ""
database = "database name"
mysql_driver = "MySQL ODBC 5.2 ANSI Driver"

//Build the connection string
Dim connectionString As String

connectionString = "Driver={" & mysql_driver & "};Server=" & location & ";Database=" & database & ";UID=" & user & ";PWD=" & password

//Create and open a new connection to the selected source
Set OpenConnection = New ADODB.connection
OpenConnection.CursorLocation = adUseClient
Call OpenConnection.Open(connectionString)
End Function

最佳答案

您需要修改MySQL中的用户帐户。可以修改允许用户连接的位置及其凭据。看这篇文章:

Allow all remote connections, MySQL

关于mysql - Excel VBA连接远程MySQL数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19448205/

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