1. 编译mysql 插件驱动
不想编译的我编译好了:sqldrivers.rar-MySQL文档类资源-CSDN文库https://download.csdn.net/download/liyang_nash/35131774
前提:安装QT的时候,记得勾选sources
打开qt安装目录, 例如目录D:\install\qt5_12_11\5.12.11\Src\qtbase\src\plugins\sqldrivers\mysql\mysql.pro
双击pro,用QTCreator打开,做如下修改:
(1)qsqldriverbase.pri文件
#lynash include($$shadowed($$PWD)/qtsqldrivers-config.pri)
include(./configure.pri)
(2)mysql.pro
TARGET = qsqlmysql
HEADERS += $$PWD/qsql_mysql_p.h
SOURCES += $$PWD/qsql_mysql.cpp $$PWD/main.cpp
#QMAKE_USE += mysql
OTHER_FILES += mysql.json
PLUGIN_CLASS_NAME = QMYSQLDriverPlugin
include(../qsqldriverbase.pri)
INCLUDEPATH +=E:/install/mysql-8.0.16-winx64/include/
LIBS += E:/install/mysql-8.0.16-winx64/lib/libmysql.lib
DESTDIR = ../mysql/mysqlDll
然后点击 "重新构建". 重新构建划重点.
(3)编译后的文件如下:
D:\install\qt5_12_11\5.12.11\Src\qtbase\src\plugins\sqldrivers\mysql\mysqlDll\
qsqlmysql.dll qsqlmysql.lib qsqlmysqld.dll qsqlmysqld.lib
(4) 把有用的文件拷贝到如下路径:
D:\install\qt5_12_11\5.12.11\msvc2017_64\plugins\sqldrivers\
qsqlmysql.dll qsqlmysql.lib qsqlmysqld.dll qsqlmysqld.lib
2. 拷贝mysql安装目录库到qt编译bin目录下
没有的可以下载:
libmysql.libeay32等4个库.rar-MySQL文档类资源-CSDN文库https://download.csdn.net/download/liyang_nash/35131644
(1) E:\install\mysql-8.0.16-winx64\bin\
ssleay32.dll, libeay32.dll
(2) E:\install\mysql-8.0.16-winx64\lib\
libmysql.dll, libmysql.lib
以上拷贝到
D:\install\qt5_12_11\5.12.11\msvc2017_64\bin\
3. QT可以连接mysql8.0了
记得, 用release编译, release划重点.