delphi中用dbexpress连接MySql5

解决:
http://www.justsoftwaresolutions.co.uk/delphi/dbexpress_and_mysql_5.html有解决方案。支持5.0.x版本。
下载后的配置
在/delphi7/dbexpress/dbxdrivers.ini 添加[MYSQL5]节:
[MYSQL5]
GetDriverFunc=getSQLDriverMYSQL50
LibraryName=dbxopenmysql50.dll
VendorLib=libmysql50.dll
BlobSize=-1
Database=DBNAME
ErrorResourceFile=
HostName=ServerName
LocaleCode=0000
Password=password
User_Name=user
ServerCharSet=GBK

在/delphi7/dbexpress/dbxdrivers.ini的 [Installed Drivers] 节追加一行:
MYSQL5=1

然后dbExpress面板的TSQLConnection就可以可视化配置了。
libraryName改成(path) debopenmysql50.dll  如 c:/debopenmysql50.dll
getDriverFunc也改成getSQLDriverMYSQL50<-這個是上面那個dll裡面的function
vendorLib 旁邊打(path)libmysql.dll   如 c:/libmysql.dll
記得要用mysql5.0裡面付的libmysql.dll
libmySQL.dll 以及 dbxopenmysql50.dll 放在程式資料夾下
然後照一般的設定Database、Hostname、User_Name、Password
然後連線就ok了,前提是MySql要記得開.

最终程序结构如下:
var
  Connection: TSQLConnection;
begin
  Connection := TSQLConnection.Create(nil);
  Connection.DriverName := 'dbxmysql';
  Connection.GetDriverFunc := 'getSQLDriverMYSQL50';
  Connection.LibraryName := 'dbxopenmysql50.dll';
  Connection.VendorLib := 'libmysql.dll';
  Connection.Params.Append('Database=NAME_OF_DATABASE);
  Connection.Params.Append('User_Name=NAME_OF_USER');
  Connection.Params.Append('Password=PASSWORD');
  Connection.Params.Append('HostName=localhost');
  Connection.Open;

  // ... do stuff

  Connection.Free;
end;

或者
        conn.ConnectionName      = "<连接名>";
        conn.DriverName          = "MYSQL5";
        conn.GetDriverFunc       = "getSQLDriverMYSQL50";
        conn.KeepConnection      = true;
        conn.LibraryName         = "dbxopenmysql50.dll";       
        conn.LoadParamsOnConnect = false;
        conn.LoginPrompt         = false;
        conn.VendorLib           = "libmysql50.dll";
        conn.Params.Append("Database=<数据库名>");
        conn.Params.Append("User_Name=<用户名>");
        conn.Params.Append("Password=<密码>");
        conn.Params.Append("HostName=<主机名名>");
        conn.Params.Append("ServerCharSet=UTF-8");  //或者GBK/GB2312

        conn.Open();
        // DB操作
        conn.Close();

参见
http://delphi.ktop.com.tw/board.php?cid=168&fid=918&tid=839939(台湾)
http://www.kaimei.org/doc/skillup/dbx_mys1.html(日文)

补:
风林火山有3篇文章讨论此问题.http://blog.csdn.net/freewind88/category/221073.aspx

你可能感兴趣的:(数据库,mysql,user,database,Path,Delphi)