Delphi7连接MySql5.5.15_MySQL
Delphi 7连接MySql 5.5.15
1.ODBC方式必须要先有MySql的ODBC驱动,我下载的是全安装版,包括MySql服务器、各种所支持的连接、工作台、示例数据库、文档,若是无ODBC驱动,可以到官网http://dev.mysql.com/downloads/connector/odbc/下载。
①数据源方式
首先,确认安装了MySql的ODBC驱动,打开“控制面板”→“管理工具”→“数据源”,切换到“驱动程序”页,查看“MySql ODBC 5.1 Driver",如下图所示:

切换到"系统DSN"→"添加"→"MySql ODBC 5.1 Driver",如下图所示:

弹出MySql数据源配置,数据源名称随意,TCP/IP Server为数据库地址,User用户名,Password密码,Database连接的数据库,点"Test"进行测试连接,如下图所示:

点击"OK"后,即可看到新增加了一个数据源。打开Delphi 7,在窗体上放置TADOConnection、TADOQuery、TDataSource和TDBGrid,相互之间关联,配置TADOConnection的连接字符串,"提供程序"选择"Microsoft OLE DB Provider for ODBC Drivers",下一步,选择"使用数据源名称",下拉选择刚才配置的数据源,其他的不用再填写,测试连接,如下图所示:

②驱动方式
跟上面一样,先确认安装MySql的ODBC驱动。打开Delphi 7,在窗体上放置TADOConnection、TADOQuery、TDataSource和TDBGrid,相互之间关联,配置TADOConnection的连接字符串,为以下内容:
1 Driver={MySQL ODBC 5.1 Driver}; Server=127.0.0.1; Database=world; User=root; Password=a123; Option=3; 在TADOQuery写查询语句,设置Active为True,数据都显示在表格上,如下图所示:

2.ZeosLib方式
ZeosLib是一个用于Borland开发工具的数据库中间件,包括Delphi、C++ Builder和Kylix。从http://sourceforge.net/projects/zeoslib/files/下载"ZEOSDBO-6.6.6-stable"版本,解压到文件夹。打开Delphi 7,加载工程项目包".../ZEOSDBO/packages/delphi7/ZeosDbo.bpg",按顺序编译,或者右键选择"Compile All From Here",如下图所示:

编译完成后,再选择"ZComponentDesign.bpl",右键选择"Install",安装组件成功,弹出如下对话框:

再添加所编译完成的目录,即".../ZEOSDBO/packages/delphi7/build",菜单"Tools"→"Environment Options"→"Library"→"Library path",添加此目录。另外,若需要在编写代码时,能进入ZeosLib源代码的话,需要添加源代码文件夹目录,包括:".../ZEOSDBO/src/core"、".../ZEOSDBO/src/parsesql"、".../ZEOSDBO/src/plain"、".../ZEOSDBO/src/dbc"和".../ZEOSDBO/src/component"(注意:会在这些目录下再次编译单元文件)。
新建一个应用程序,在窗体上放置TZConnection、TZQuery、TDataSource和TDBGrid,在窗体创建函数里,写入以下代码:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19 procedure TForm1.FormCreate(Sender: TObject);
begin
//---------------互相关联------------------------
zqry1.Connection := zcon1;
ds1.DataSet := zqry1;
dbgrd1.DataSource := ds1;
//---------------设置参数------------------------
zcon1.Protocol := 'mysql';
zcon1.Port := 3306;
zcon1.HostName := '127.0.0.1';
zcon1.User := 'root';
zcon1.Password := 'a123';
zcon1.Database := 'world';
zcon1.Connected := True;
//---------------查询显示------------------------
zqry1.Close;
zqry1.SQL.Text := 'SELECT * FROM City';
zqry1.Active := True;
end; 当然手动在设计器上进行设置也可以。因为这里连接的是MySql数据库,需要拷贝MySql数据库客户端所需的DLL(即:libmysql.dll,这里我安装的是在".../MySQL/MySQL Server 5.5/lib"里面)复制到Windows系统目录(通常是"C:/WINDOWS/system32")或者工程目录下。程序如下图所示:

当程序发给别人使用时,需要连同"libmysql.dll"一起发送。若是显示的数据有乱码,这是因为MySQl数据库默认使用UTF-8字符集,则先在查询之前,设置字符集,如下代码所示:
1
2
3
4
5
6
7 begin
zqry1.Close;
zqry1.SQL.Text := 'set names gbk';
zqry1.ExecSQL;
zqry1.SQL.Text := 'select * from city';
zqry1.Active := True;
end;
或者在TZConnection的Properties属性添加"codepage=gbk"。
3.其他方式
另外,还有其他的第三方控件可以连接MySql等其他数据库,如:AnyDAC、MyDAC 、DAC for MySQL等等。
扩展资料:1.MySQL with Delphi http://delphi.about.com/od/mysql/MySQL_with_Delphi.htm
2.Zeoslib Portal :: Home http://zeos.firmos.at/
3.使用ZeosDbo元件

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

LaravelEloquent Model Retrieval: Easily obtaining database data EloquentORM provides a concise and easy-to-understand way to operate the database. This article will introduce various Eloquent model search techniques in detail to help you obtain data from the database efficiently. 1. Get all records. Use the all() method to get all records in the database table: useApp\Models\Post;$posts=Post::all(); This will return a collection. You can access data using foreach loop or other collection methods: foreach($postsas$post){echo$post->

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.
