Windows platform MinGW compiler MySQL

Source: Internet
Author: User
Tags rar win32

This article applies only to the Windows platform MinGW compiler

System: Windows XP
QT Version: 4.8.0
Qt Creator version: 2.4.1

Installation path:
Qt-D:\Qt\4.8.0
Qt Creator-D:\Qt\qtcreator-2.4.1
MinGW-D:\Qt\qtcreator-2.4.1\mingw

1. Configure Environment variables:

Edit path in the system variable--environment variable, properties---
;D: \qt\4.8.0\bin;d:\qt\qtcreator-2.4.1\bin;d:\qt\qtcreator-2.4.1\mingw\bin
To make the environment variable effective, if you have already opened CMD before configuring the environment variable, reopen a new cmd window.

2. Download MySQL

Official website www.mysql.com download, the file name of the non-installation package is similar to this format: Mysql-5.5.29-win32.zip
I downloaded the installation package: Http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.29-win32.zip
Just need Lib and include in MySQL, so here I provide a thin package: Mysql_lib_include.rar
Unzip to D:\

3. Download mingw-utils-0.3.tar.gz,

Extract, the bin folder inside the Reimp.exe copy to the D:\Qt\qtcreator-2.4.1\mingw\bin directory, do not copy also line, call Reimp manually add absolute path.


4. Compiling the driver

Open cmd and execute the following command:

(1) Convert libmysql format

D:
CD D:\mysql\lib
Reimp-d Libmysql.lib
Dlltool-k-D libmysql.def-l LIBMYSQL.A

(2) compiling QT mysql driver

[plain] view plain copy

  1. CD D:\qt\4.8.0\src\plugins\sqldrivers\mysql

  2. Qmake "Config+=release"-O Makefile "includepath+=d:/mysql/include" "LIBS+=D:/MYSQL/LIB/LIBMYSQL.A" Mysql.pro

  3. Mingw32-make

  4. Qmake "Config+=debug"-O Makefile "includepath+=d:/mysql/include" "LIBS+=D:/MYSQL/LIB/LIBMYSQL.A" Mysql.pro

  5. Mingw32-make


5. Copy MySQL driver

After compiling, open the D:\Qt\4.8.0\src\plugins\sqldrivers\mysql directory, you can see the release and Debug directories, respectively, from the release and debug directory to copy the following 4 files to D:\Qt\4.8.0 \plugins\sqldrivers:
Qsqlmysql4.dll
libqsqlmysql4.a
Qsqlmysqld4.dll
libqsqlmysqld4.a

6. Copy MySQL dynamic library (important)(1) operation of the machine

Copy D:\mysql\lib\libmysql.dll files to D:\Qt\4.8.0\bin

(2) computer without MySQL

To publish an application, follow the Libmysql.dll piece to publish it with the application sibling directory.

7. Test MySQL availability

To join a MySQL service that already exists, write the following code test:

(1). Test if there is a driver

[CPP] view plain copy

  1. Qstringlist driverlist = qsqldatabase::d rivers ();

  2. Qdebug () << driverlist;

  3. //Running results: ("Qsqlite", "QMYSQL3", "Qmysql", "QODBC3", "Qodbc")?   

If there's qmysql and QMYSQL3, it's right.

(2). Test whether MySQL is available

[CPP] view plain copy

  1. Qsqldatabase db = qsqldatabase::adddatabase ("Qmysql");

  2. Db.sethostname ("192.168.1.23");

  3. Db.setdatabasename ("Testsql");

  4. Db.setusername ("root");

  5. Db.setpassword ("root");

  6. BOOL  OK = Db.open ();

  7. Qdebug () << OK;

  8. //Run Result: true   

True to indicate a successful connection

8. Provide MySQL driver for successful compilation

My version above has been written: Windows, Qt4.8, MinGW
: Qt4.8_mingw_qsqlmysql4.rar


Windows platform MinGW compiler MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.