前提:
安装mysql odbc驱动程序,目前只不支持8.0的最新版本驱动,个人使用的是5.1.12的驱动(不支持5.2以上版本),下载地址为:
x64: https://cdn.mysql.com/archives/mysql-connector-odbc-5.1/mysql-connector-odbc-5.1.12-winx64.msi
x32:https://cdn.mysql.com/archives/mysql-connector-odbc-5.1/mysql-connector-odbc-5.1.12-winx32.msi
64位机器连接字符串:
"Provider=MSDASQL;Driver={MySQL ODBC 5.1 Driver}; Server = 192.168.1.252;Database = rentaldw;charset = UTF8; Port=9030;User = root; Password = root; Option = 3; ";
32位机器连接字符串:
"Driver={MySQL ODBC 5.1 Driver}; Server = 192.168.1.252;Database = rentaldw;charset = UTF8; Port=9030;User = root; Password = root; Option = 3; ";
使用System.Data.OdbcConnection来进行操作.
const string CONNECTIONSTRING = "Provider=MSDASQL;Driver={MySQL ODBC 5.1 Driver};Server=192.168.4.164;" + "Port=9030;charset=UTF8;Database=dw_sales;User=root;Password=root;Option=3;"; OdbcConnection connection = new OdbcConnection(CONNECTIONSTRING); DataSet dataset=new DataSet(); var command = new OdbcCommand("SELECT budget_name FROM dim_BudgetLibrary",connection); var adapter = new OdbcDataAdapter(command); connection.Open(); adapter.Fill(dataset); connection.Close();