配置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 .
本文详细指导如何在Qt 6.2中使用嵌入式MySQL服务器,包括链接库步骤,依赖安装,以及在Unix和macOS上编译QMYSQLPlugin的教程。特别强调了如何设置MySQL头文件和库路径以完成编译过程。

967

被折叠的 条评论
为什么被折叠?



