The complete process of QT MySQL driver compilation (using QT creator)

Source: Internet
Author: User
Tags administrator password

First, pre-installation preparation

1, download the installation package, can go to MySQL official website www.mysql.com download, 1-1:

Figure 1-1

Download the installation file as shown in 1-2 :

Figure 1-2

Second, installation

1, double-click the downloaded installation file, this blog post installs the MySQL version is 5.6.10.1, the page appears 1-3:

Figure 1-3

2. Click "Install MySQLProducts" to enter the 1-4 page:

Figure 1-4

3, tick "I accept the License Terms", click "Next", appear 1-5 to find the latest product update page, do not like to update, you can choose "Skip the Check for updates" below Recommended) ", click on" Next "to continue:

Figure 1-5

4, according to the right installation type description file to choose the appropriate installation type,1-6 , note that modify the installation path, in order to prevent reloading the system, you need to install MySQLagain:

Figure 1-6

5, depending on the type of installation you choose, you will need to install some framework (Framework), click "Execute" To install the required framework,1-7 :

Figure 1-7

6, the installation of the framework in the process of the page,1-8:

Figure 1-8

7, the framework after the successful installation of the prompt,1-9:

Figure1-9

8,the required framework is installed successfully,1-10, click "Next":

Figure 1-10

9, start the installation,1-11, click "Execute", the installation process of the interface 1-12:

Figure 1-11

Figure 1-12

configuration information, 1-13, click "Next":

Figure 1-13

11, server Configuration type selection,Developer Machine--Installation ofMySQLserver as part of the development machine, in three types of selection, the use of the least memory;Server Machine--Installation ofMySQLserver as part of the server machine, occupy within three types in the center;dedicated MySQL Server machine--Special installationMySQLThe database server, which occupies all the valid memory of the machine. Do not modify, default port3306Do not change, click on the "Next":

Figure 1-14

,set the administrator password,1-15, select "Adduser", you can create a user, from a security perspective it is best not to create a user:

Figure 1-15

In the 1-16 interface, you can set the system server name, whether the system is started automatically automatic MySQL database server, the default options available, click " Next ":

Figure 1-16

confirm the installation is complete, check "Start MySQL Workbench after Setup" To test the successful installation, click "Finish":

Figure 1-17

Third, the installation is successful

1, appeared Workbench GUI page,1-18, installation success:

To compile the MySQL project steps:

The next step is to open the MySQL project with Qt Creator, where the project path is in D:\Qt\4.8.4\src\plugins\sqldrivers\mysql (the specific path is selected based on your own installation directory).

Go to MySQL installation directory and copy Lib/libmysql.dll and Lib/libmysql.lib to D:\Qt\4.8.4\src\plugins\sqldrivers\mysql

Edit the Mysql.pro file in the directory

QT +=sql
Includepath +=d:\mysql\include
LIBS + =-ld:\mysql\lib\-llibmysql

Note that this must be filled out or will error (can not find-llibmysql)
Where Mysql\include and Lib are I copied from the MySQL installation directory to create a new folder, the directory can not have spaces, or will be error,
This completes the pre-compilation work.
    1. In this way, the debug directory and the release directory under the C:\QT\4.8.6\src\plugins\sqldrivers\mysql directory will be generated separately.

      Qsqlmysqld4.dll Qsqlmysqld4.lib

      Qsqlmysql4.dll Qsqlmysql4.lib

    2. Copy the four files mentioned above to

      D:\Qt\4.8.4\plugins\sqldrivers

    3. Finally put

      C:\mysql\lib\libmysql.dll

      C:\mysql\lib\libmysql.lib

      The C:\Windows\system32\ directory.

      4, if you want to run in this machine will also need to

      Copy to Lib\libmysql.dll file to D:\Qt\4.8.4\bin

So the driver installed successfully, the next job is to verify that the driver is not successful, the best way is to write a test MySQL connection program, did so long work is a harvest time, nonsense not to say, directly on the code, this is a good way, the code is as follows:

test MySQL availability

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

(1).Test If there is a driver
    1. Qstringlist driverlist = qsqldatabase::d rivers ();  Qdebug () << driverlist;  

        

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

(2).test whether MySQL is available
      1. To test MySQL availability into a MySQL service that already exists, write the following code test: (1). Test if there is a drive [CPP] View plaincopyqstringlist driverlist = qsqldatabase::d rivers ();  Qdebug () << driverlist;  Running results: ("Qsqlite", "QMYSQL3", "Qmysql", "QODBC3", "Qodbc")?  If the presence of Qmysql and QMYSQL3 is correct (2). Test whether MySQL is available [CPP] View Plaincopyqsqldatabase db = Qsqldatabase::adddatabase ("Qmysql");  Db.sethostname ("192.168.1.23");  Db.setdatabasename ("Testsql");  Db.setusername ("root");  Db.setpassword ("root");  bool OK = Db.open ();  Qdebug () << OK;  Run Result: true  

          

The complete process of QT MySQL driver compilation (using QT creator)

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.