我正在开发一个Excel VBA项目,我使用ADODB连接到MySQL服务器,但我无法弄清楚如何将端口信息添加到连接字符串。我的连接代码工作,因为我连接到其他数据库,但我最近移动到我的本地计算机,我有多个连接,每个连接在一个不同的端口。这是我当前的连接字符串:
''''''''''''''''''''''''''''''''''''''''''''''''
' My Laptop Connection
''''''''''''''''''''''''''''''''''''''''''''''''
Public Const server_name As String = "127.0.0.1:5353" 'Enter your server name here - if running from a local computer use 127.0.0.1 or localhost
Public Const database_name As String = "juice" 'Enter your database name here
Public Const user_id As String = "root" 'Enter your user ID here
Public Const password As String = "Password1" 'Enter your password here
Public Const MySQLConnectStr As String = "DRIVER={MySQL ODBC 5.3 ANSI Driver}" _
& ";SERVER=" & server_name _
& ";DATABASE=" & database_name _
& ";UID=" & user_id _
& ";PWD=" & password _
& ";OPTION=16427"
答案 0 :(得分:2)
好的,我在connectionstrings.com上发现了它 - http://www.connectionstrings.com/mysql-connector-odbc-5-2/
您在单独的参数中提供端口。请参阅下面的固定代码。
''''''''''''''''''''''''''''''''''''''''''''''''
' My Laptop Connection
''''''''''''''''''''''''''''''''''''''''''''''''
Public Const server_name As String = "127.0.0.1" 'Enter your server name here - if running from a local computer use 127.0.0.1 or localhost
Public Const database_name As String = "juice" 'Enter your database name here
Public Const user_id As String = "root" 'Enter your user ID here
Public Const password As String = "Password1" 'Enter your password here
Public Const port As String = "5353" 'If a specific port enter here. connection string uses 3306 by default.
Public Const MySQLConnectStr As String = "DRIVER={MySQL ODBC 5.3 ANSI Driver}" _
& ";SERVER=" & server_name _
& ";PORT=" & port _
& ";DATABASE=" & database_name _
& ";UID=" & user_id _
& ";PWD=" & password _
& ";OPTION=16427"