连接错误:Excel VBA到远程MySQL

时间:2014-11-22 23:34:13

标签: mysql excel vba excel-vba odbc

我有两台工作电脑,在同一个网络上,同一个公共IP。我能够从计算机上的localhost成功连接到我的mySQL数据库1.我正在尝试通过Excel VBA从计算机2连接到同一个数据库。我试过了

mysql> GRANT ALL PRIVILEGES ON database.* to user@'ip' IDENTIFIED BY 'pass'
mysql> GRANT ALL PRIVILEGES ON database.* to user@'%' IDENTIFIED BY 'pass'

Excel VBA:

Dim strServer As String
Dim strDBName As String
Dim strUserID As String
Dim strPasswd As String

strServer = "ipaddress"
strDBName = "dbname"
strUserID = "userid"
strPasswd = "pass"

Set oConn = New ADODB.Connection
  With oConn
    .ConnectionString = "Driver={MySQL ODBC 5.2 Unicode Driver};" & _
          "Server=" & strServer & ";Port=3306;" & _
          "Database=" & strDBName & ";" & _
          "Uid=" & strUserID & ";" & _
          "Pwd=" & strPasswd & ";Option=3;"
     .Open
End With

MsgBox "Connection Successful"

Excel VBA错误:

  

“运行时错误'-2147467259(800004005)':[MySQL] [ODBC 5.2(w)   驱动程序]无法在'ip'(10061)“

上连接到MySQL服务器

我的语法是否在某处,或者我错过了什么? (我还有3台其他工作计算机,在不同的网络上,我想授予类似的权限,因为它们都使用共享的Excel工作簿)。

1 个答案:

答案 0 :(得分:0)

也许GRANT ALL PRIVILEGES ON database.* 'user'@'ip' IDENTIFIED BY 'pass'会为你做的伎俩。根据{{​​3}},用户名也在引号中。