The example in this article describes the implementation method of Delphi remote connection to Mysql, which is a very important skill in Delphi database programming. Share it with everyone for your reference. The specific method is as follows:
Delphi connects to the remote Mysql database through ADOConnection. You need to install the Mysql driver on the computer where the software is installed. If it is not available, download it from Baidu. Search for the mysql ODBC driver and it will come out.
The main link code is as follows:
var srstring:string;srstring:='DRIVER={MySQL ODBC 3.51 Driver};SERVER='+Trim(SERVER.Text)+';DATABASE='+Trim(DATABASE.Text)+';USER='+Trim(USER.Text)+';PASSWORD='+Trim(PASSWORD. Text)+';OPTION='+Trim(OPTION.Text)+';charset=gb2312;';Here is an explanation of the meaning of the above variables:
DRIVER= indicates the driver name used,
SERVER= represents the mysql database address . If you are remote, just write the remote IP directly.
DATABASE= indicates the name of the database to be linked
USER= database username
PASSWORD= Database password
OPTION=indicates port
charset= indicates the character encoding used
Link data begins:
ADOConnection1.ConnectionString:=srstring;ADOConnection1.Close;ADOConnection1.Open;showmessage('save and login database success!');Finally, add the ADOConnection control to the form.
I hope this article will be helpful to everyone in Delphi database programming.