Delphi XE3通过ADOConnection 连接 MySQL 5.5.27 数据库
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Data.DB, Data.Win.ADODB, Vcl.Grids, Vcl.DBGrids; type TForm1 = class(TForm) ADOConnection1: TADOConnection; Button1: TButton; ADODataSet1: TADODataSet; DBGrid1: TDBGrid; DataSource1: TDataSource; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin { 从https://dev.mysql.com/downloads/connector/odbc/下载 mysql-connector-odbc-5.3.4-win32.msi 安装msi后在Winodws系统控制面板中的“管理工具”中的“ODBC数据源管理器”中
切换到“系统DSN”选项卡点击“添加”后可以看到已经安装的MYSQL 驱动程序,
例如有: MySQL ODBC 5.3 Unicode Driver MySQL ODBC 5.3 ANSI Driver MySQL数据库版本为: mysql Ver 14.14 Distrib 5.5.27, for Win32 (x86) DELPHI XE3 下测试通过 } ADOConnection1.ConnectionString:= ('DRIVER={MySQL ODBC 5.3 Unicode Driver};'+ 'SERVER=localhost;'+ 'DATABASE=test;'+ 'USER=root;'+ 'PASSWORD=toor;'+ 'OPTION=3;'); ADOConnection1.LoginPrompt:=FALSE; ADOConnection1.Close; ADOConnection1.Open(); ADODataSet1.Connection:=ADOConnection1; ADODataSet1.CommandText:='select * from user'; DataSource1.DataSet:=ADODataSet1; DBGrid1.DataSource:=DataSource1; ADODataSet1.Active:=true; end; end.