delphi连接mysql

首先在窗体上拖拽sqlconnection和sqlquery两个控件

然后在测试连接中,写入以下代码(注意exe生成目录下需要有dbxopenmysql50.dll和libmysql.dll

SQLConnection1 := TSQLConnection.Create(nil);
   SQLConnection1.DriverName := 'dbxmysql';
   SQLConnection1.GetDriverFunc := 'getSQLDriverMYSQL50';
   SQLConnection1.LibraryName := 'dbxopenmysql50.dll';
   SQLConnection1.VendorLib := 'libmysql.dll';
   SQLConnection1.LoginPrompt := false;
   SQLConnection1.Params.Append('Database=sampledb31');
   SQLConnection1.Params.Append('User_Name=test');
   SQLConnection1.Params.Append('Password=test');
   SQLConnection1.Params.Append('HostName=192.168.1.78');

   SQLConnection1.Open;
    if SQLConnection1.Connected = true then
    begin
      SQLQuery1.SQLConnection := SQLConnection1;
      SQLQuery1.SQL.Clear;
      SQLQuery1.SQL.Text := 'SET NAMES gbk;';//设置mysql查询中文不乱码
      SQLQuery1.ExecSQL();
      MessageBox(0,'连接成功','提示',MB_ICONASTERISK and MB_ICONINFORMATION);
    end else
    begin
      showmessage('数据库连接失败!');
      SQLConnection1.Close;
    end;
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值