linux qt 5.12.6 编译mysql驱动

环境:ubuntu 18.4 x64、qt 5.12.6

问题:安装后是没有mysql的驱动的

解决过程:

各种搜索,先后安装了mysql mysql-client,mysql-server,和各种libdev之类的东西,好像和结果没啥关系

隔了一天,继续搜索,试了个法子,一次性成功了,是qt 官方论坛里的一个评论:

灰色字体的不用看了,介绍背景的,红色字体是我加的说明

brochiha 2019年10月28日 下午11:22

These are the instruction that I made after installed it on my Ubuntu 18.04 linux install. Maybe it will help you
Download QT 5.12.4 from QT website using the downloads buttons and then select open source and download

After Download is complete go to Downloads folder and run the installer
(for new ubuntu users – right click on file in downloads and select permissions and select option at bottom)

Download latest QT that is known to have LTS (long term support)
-Run installer
-deselect android stuff and make sure that you select the dev tools and sources at the bottom
install QT

download and install mysql and dev packages

sudo apt-get install libglu1-mesa-dev
sudo apt-get install build-essential
sudo apt-get install libmysqlclient-dev
sudo apt-get install libssl-dev

注:上面这几句估计就是我昨天安装的那堆东西里都有的,今天没再执行;应该是必须的。

navigate to your Qt folder/5.12.4/Src
-run config file
./configure -plugin-sql-mysql

Navigate to qt source ie...Qt/5.12.4/Src/qtbase/src/plugins/sqldrivers/mysql
-run the QT qmake

  • #根据自己安装的目录调整实际路径
  • #我的qt装在了/home/Qt/5.12.6/gcc_64....
  • #MYSQL_PREFIX=后面是需要引用的mysql相关的头文件的路径,不知道的化,可以执行whereis mysql命令
  • #列出的路径里应该有include/mysql之类的,自己进去看看里面的内容就确定是不是了;

/home/bj/Qt/5.12.4/gcc_64/bin/qmake MYSQL_PREFIX=/usr/include/mysql/ mysql.pro
locations may vary depending on where you installed Qt during the installation process and what version of Ubuntu you may be using
after running qmake
-run make
-make install

然后再去qt安装目录,/home/key/Qt/5.12.6/gcc_64/plugins/sqldrivers,已经生成了msyql的库文件

上一篇:国际奥林匹克日 | 与TcaplusDB动起来!


下一篇:Redis从入门到精通:中级篇(转)