Excel VBA 连接到远程 MySQL 数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19448205/
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
Excel VBA connecting to remote MySQL Database
提问by harryg
i am using the OBDC connector to use VBA to connect to my MySQL database. It currently runs on a local webserver (localhost) but is accessible from other PCs on the network via my PC's IP address.
我正在使用 OBDC 连接器使用 VBA 连接到我的 MySQL 数据库。它目前在本地网络服务器 (localhost) 上运行,但可以通过我 PC 的 IP 地址从网络上的其他 PC 访问。
In my connection function I had localhost
as the location but when I change it to my IP address I get an
在我的连接功能中,我有localhost
作为位置,但是当我将其更改为我的 IP 地址时,我得到一个
[MySQL][ODBC 5.2 Driver] (my computer name) is not allowed to connect to this MySQL server
[MySQL][ODBC 5.2 Driver] (my computer name) is not allowed to connect to this MySQL server
error.
错误。
I presume this is a security problem. Any way to fix this?
我认为这是一个安全问题。有任何解决这个问题的方法吗?
Here is my connection function:
这是我的连接功能:
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
回答by pcreech
You need to modify the user account in MySQL. It is possible to modify the locations users are allowed to connect from and their credentials. Look at this post:
您需要修改 MySQL 中的用户帐户。可以修改允许用户连接的位置及其凭据。看看这个帖子: