VBA连接到远程MySQL数据库

VBA连接到远程MySQL数据库

本文介绍了Excel VBA连接到远程MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

在连接功能中,我以localhost作为位置,但是当我将其更改为IP地址时,会得到一个

In my connection function I had localhost as the location but when I change it to my IP address I get an

错误.

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

I presume this is a security problem. Any way to fix this?

这是我的连接功能:

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中修改用户帐户.可以修改允许用户连接的位置及其凭据.看这篇文章:

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

这篇关于Excel VBA连接到远程MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 00:09