QT6编译安装mysql驱动解决QMYSQL driver not loadedsql

配置mysql驱动

  • 官方网址

https://doc.qt.io/qt-6.2/sql-driver.html

  • 官网文档解释

Embedded MySQL Server
The MySQL embedded server is a drop-in replacement for the normal client library. With the embedded MySQL server, a MySQL server is not required to use MySQL functionality.

To use the embedded MySQL server, simply link the Qt plugin to libmysqld instead of libmysqlclient. This can be done by adding -DMySQL_LIBRARY=<path/to/mysqld/>libmysqld.<so|lib|dylib> to the configure command line.

Please refer to the MySQL documentation, chapter “libmysqld, the Embedded MySQL Server Library” for more information about the MySQL embedded server.

How to Build the QMYSQL Plugin on Unix and macOS
You need the MySQL / MariaDB header files, as well as the shared library libmysqlclient.<so|dylib> / libmariadb.<so|dylib>. Depending on your Linux distribution, you may need to install a package which is usually called “mysql-devel” or “mariadb-devel”.

Tell qt-cmake where to find the MySQL / MariaDB header files and shared libraries (here it is assumed that MySQL / MariaDB is installed in /usr/local) and build:

mkdir build-sqldrivers
cd build-sqldrivers

qt-cmake -G Ninja <qt_installation_path>/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DMySQL_INCLUDE_DIR="/usr/local/mysql/include" -DMySQL_LIBRARY="/usr/local/mysql/lib/libmysqlclient.<so|dylib>"
cmake --build .
cmake --install .
  • 自定义修改整理后如下
ln -s /opt/Qt/Tools/Ninja/ninja /usr/bin/ninja-build
mkdir build-sqldrivers
cd build-sqldrivers
/opt/Qt/6.*/gcc_64/bin/qt-cmake -G Ninja /opt/Qt/6.*/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=/opt/Qt/6.2.4/gcc_64 -DMySQL_INCLUDE_DIR="/usr/include/mysql" -DMySQL_LIBRARY="/lib64/libmysqlclient.so"
cmake --build .
cmake --install .
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NoYoWiFi

感谢大佬赐赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值