zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

t-ora issue can't login mysql

mysql &# 39 can login issue ORA
2023-09-11 14:18:40 时间

 

https://github.com/tora-tool/tora/issues/99

 

###

TOra is an open-source multi-platform database management GUI that supports accessing most of the common database platforms in use, including Oracle, MySQL, and PostgreSQL, as well as limited support for any target that can be accessed through Qt's ODBC support. TOra has been built for various Linux distributions, Mac OS X, MS Windows, and UNIX platforms.

.ddl 文件是已经编译好的文件,直接放在exe 执行文件同一个目录下,不需要编译,可以识别

.a  文件是没有编译过的。需要编译

###新的版本 Qt 5  (推荐 )

 

首先遇到的问题,如下:

QSqlDatabase: QMYSQL driver not loaded

QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7

Unable to open database

网上大部分帖子都是提出重新编译驱动,其实并不需要这么麻烦。

    首先要理解驱动不匹配是怎么回事。我所遇到的问题是我的qt是32位的,但是Mysql却是64位的。使用32位的编译器调用64位的libmysql.dll肯定是不可能调用成功。因此我们只需要到mysql官网下载符合你编译器的dll库就可以。

下载网站:https://dev.mysql.com/downloads/connector/c/

选择符合你的编译器的动态库(32位编译器就下载32位的dll),下载下来。之后将libmysql.dll拷贝到C:\Qt\Qt5.7.0\5.7\mingw53_32\bin目录下即可。

再做连接mysql操作即可发现连接成功。

 

解决方法:

t-ora 是64bit ,所以下载64bit 的 mysql-connector-c-6.1.11-winx64.zip,然后将其中lib/libmysql.dll 文件copy 到tora 目录下即可,tora 目录下原有的libmysql.dll 需要改名即可。

 

######参考1

https://blog.csdn.net/u012997311/article/details/51405487

https://blog.csdn.net/Rexlfs/article/details/64906328

Qt不能加载MySql驱动问题 (无需重新编译驱动)

首先遇到的问题,如下:

QSqlDatabase: QMYSQL driver not loaded

QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7

Unable to open database

网上大部分帖子都是提出重新编译驱动,其实并不需要这么麻烦。

    首先要理解驱动不匹配是怎么回事。我所遇到的问题是我的qt是32位的,但是Mysql却是64位的。使用32位的编译器调用64位的libmysql.dll肯定是不可能调用成功。因此我们只需要到mysql官网下载符合你编译器的dll库就可以。

下载网站:https://dev.mysql.com/downloads/connector/c/

选择符合你的编译器的动态库(32位编译器就下载32位的dll),下载下来。之后将libmysql.dll拷贝到C:\Qt\Qt5.7.0\5.7\mingw53_32\bin目录下即可。

再做连接mysql操作即可发现连接成功。

 

 

###参考2

Qt5.7中使用MySQL Driver(需要把libmysql.dll文件拷贝到Qt的bin目录中。或者自己编译的时候,链接静态库)

 

Qt5.7中使用MySQL Driver

1、使用环境

Qt5.7的安装安装就已经带了MySQL Driver,只需要在安装的时候选择一下即可。
如果没有安装,可以采取自己编译的方式。
在Qt的源码包的qtbase\src\sql\drivers\mysql路径下,就是相关的源码文件。
这里就不说编译方式了。只是要记得在编译的时候,需要libmysql的支持。

2、基本使用

    QSqlError err;
    // 数据库对象创建
    QSqlDatabase db = QSqlDatabase::addDatabase("MYSQL","连接名");
    // 设置相关参数
    db.setDatabaseName("数据库名");    // 需要与数据库中的一致
    db.setHostName("127.0.0.1");    // 主机名(地址)
    db.setPort(3366);        // 端口

    // 打开数据库
    if (!db.open("用户名", "密码")) {
        err = db.lastError();
        db = QSqlDatabase();
        QSqlDatabase::removeDatabase("连接名");
    }
    // Query对象创建
    QSqlQuery q("", db);
    // 创建一个表
    q.exec("create table Names (id integer primary key, Firstname varchar, Lastname varchar, City varchar)");
    // 插入三条数据
    q.exec("insert into Names values (1, 'Christopher', 'Walker', 'Morristown')");
    q.exec("insert into Names values (2, 'Donald', 'Duck', 'Andeby')");
    q.exec("insert into Names values (3, 'Buck', 'Rogers', 'Paris')");

3、一个小问题

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7

这里需要把libmysql.dll文件拷贝到Qtbin目录中。或者自己编译的时候,链接静态库。

 

 

 

### 老的编译编译Qt 4 的Mysql驱动 make 方法: (源代码版本,不推荐)

There is also a Mingw32 Fedora 11 Cross Compile build
  - see the README file in the win32-cross directory,
  which also contains utility scripts for that build.
   
  Content:
  - Building with MSVC - CMake
  - Building Windows installer.
   
  #
  # Building with MSVC - CMake (+ See README.CMAKE)
  #
  All information below assumes D:\DEVEL as the base directory, and
  D:\DEVEL\tora3 as tora checkout.
   
  1. Download and install "Microsoft Visual Studio 2013 Express" (or higher)
  1a. (Optional) Download and install "Microsoft DirectX SDK (June 2010)"
  1b. (Optional) Download and install "Microsoft Windows SDK v7.1".
  If you have Windows SDK 7.1 use it's command prompt.
  1c. Download and install Git for Windows (https://git-for-windows.github.io/), into D:\DEVEL (or somewhere *without* spaces in the PATH)
   
  ========================== QT 4 Version ========================================
  2. All related steps are done in the "Visual Studio Command Prompt"
  I have MS Visual Studio 2013 Express. (Or Windows SDK 7.1 command prompt).
   
  3. Download and install Active state Perl
   
  4. Download and unzip OpenSSL-<ver>.tgz
  4a. Build OpenSSL as described here: http://qt-project.org/wiki/Building_Qt_Desktop_for_Windows_with_MSVC
  4b. set environment qt32.bat (or qt64.bat)
  4b. perl Configure VC-WIN32 --prefix=D:\Devel\OpenSSL
  4c. ms\do_ms
  4d. nmake -f ms\ntdll.mak
  4e. nmake -f ms\ntdll.mak install
   
  5. Download and unzip Boost headers. The is no need to compile anything. Only few headers are needed.
   
  6. Download and unzip Qt4 source version for Windows. (Version 4.8.5)
  6a. Build OpenSSL as described here: http://qt-project.org/wiki/Building_Qt_Desktop_for_Windows_with_MSVC
  6b. Configure QT: configure.exe -debug-and-release -fast -openssl -webkit -nomake examples -nomake demos -system-proxies -stl
  6c. Compile QT: nmake (and wait)
   
  7. Install Oracle client - instant or standard one. (set env. variable ORACLE_HOME)
   
  8. (Optional) Download and install Postgresql including development packages.
  It's a part of the default install - just check its component.
  NOTE: Install it to the path *without* spaces in its name - Qt has
  problems with compilation in the case of space.
   
  URL: http://www.enterprisedb.com/products/pgdownload.do#windows
  Seems that this installer doesn't prompt for any paths/etc.
  Be sure and disable postgres service after install if you won't be running the server itself
   
  9. (Optional) Download and install MySQL including development packages.
  It's a part of default installer - just check its component.
  NOTE: Install it to the path *without* space in its name - Qt has
  problems with compilation in the case of space.
   
  URL: http://dev.mysql.com/downloads/mysql/5.1.html#win32
  I am testing with the 5.1.37 MSI installer, not the 'Essentials' one
   
  10. Compile QT DB drivers for MySQL and PostgresSQL as described here: http://qt-project.org/doc/qt-4.8/sql-driver.html
  ========================== QT 5 Version ========================================
  2. Download&Install binaries for MSVC
  2a. set env variable QTDIR in MSVC command prompt
  ================================================================================
   
  11. Download and install cmake from www.cmake.org. Into D:\DEVEL (*without* spaces in the PATH)
   
  12. Check and set paths
  - QTDIR
  - CMAKE
  - Doxygen (Optional)
  - OpenSSL
  - Nasm (Optional)
  - Perl
  - DirectX SDK (Optional)
  - Windows SDK 7.1 (Optional)
  - Tortoise SVN (svn.exe is needed while building)
  - MSVC
   
  13. Compile Tora in a GUI.
  cd d:\devel\tora3
  cmake-gui
  - Where is the source core: d:\devel\tora3
  - Where to build the binaries: d:\devel\tora3
  - Add Entry: Name: BOOST_ROOT
  Type: "Path"
  Value" "D:/DEVEL/boost_1_58_0"
  - Add Entry: Name: CMAKE_BUILD_TYPE
  Value: either "Debug", "Release" or "RelWithDebInfo"
  - Toggle WANT_INTERNAL_QSCINTILLA to Y.
  - Toggle WANT_INTERNAL_LOKI to Y.
  - Click Configure/Generate, set generator to Visual Studio 2013 (or Visual Studio 2013 64bit)
  13b. Open Visual Studio 2013 and import solution tora.sln
  13c. Compile projects tora poracle
   
  14. Compile Tora in command prompt
  mkdir d:\devel\tora3\debug
  cd d:\devel\tora3\debug
  cmake -DBOOST_ROOT=D:/DEVEL/boost_1_58_0 -DWANT_INTERNAL_QSCINTILLA=1 -DWANT_INTERNAL_LOKI=1 -DCMAKE_BUILD_TYPE=Debug -G "NMake Makefiles" ..
  nmake
   
  #
  # Testing
  #
  Above build will generate into the tora-build\RELEASE dir. Copy the various dll files from Qt, Postgres, MySQL
  installs into that dir as well:
  MSVC 2013 Runtime libs(optional)
  msvcp120.dll
  msvcr120.dll
  QT4 Libs:
  QtCore4.dll QtGui4.dll QtHelp4.dll QtNetwork4.dll QtSql4.dll QtXml4.dll (put into root)
  qsqlmysqld4.dll qsqlpsql4.dll qsqlodbc4.dll (put into plugins subdir)
  QT5 Libs:
  cd src/RelWithDebInfo
  %QTDIR%/bin/windeployqt tora.exe
   
  Tora Libs:
  poracle.dll
  trotl.dll
  Then you should be able to run tora.exe from that dir. This can be used to test prior to packaging.
   
  #
  # Building Windows installer.
  #
  MSI
  1. Download and install Wix from
  http://wixtoolset.org/
   
  2. Execute the packager
  cd package
  make_msi.bat (resp. make_msi64.bat, make_msi64_qt5.bat)
   
  Please report any bugs should you find them as this port is still in the
 

experimental stage.

 

 

 

 #### sample 测试方法 (没通过):

 

1.Download Visual Studio 2013 for Windows Version: Express Edition

https://en.softonic.com/download/visual-studio-2013/windows/post-download?sl=1

注意是 express 版不是其他版

 

Visual Studio Express 2012 for Windows Desktop
KEY : MMVJ9-FKY74-W449Y-RB79G-8GJGJ

Microsoft Visual Studio Express 2012 for Web
KEY :VX3VY-8GCVT-KJQCY-RQ99X-MCF2R


2.qt-opensource-windows-x86-msvc2015-5.7.1.exe

http://download.qt.io/official_releases/qt/5.7/5.7.1/

https://blog.csdn.net/qq_39340204/article/details/78594854?locationNum=4&fps=1

D:\Qt\Qt5.7.1


2.2 mysql
C:\wamp64\bin\mysql\mysql5.7.9\

https://blog.csdn.net/qq_39340204/article/details/78593512

2.3 t-ora
C:\Users\penghuishun.CRBCOA\AppData\Local\Apps\Tora


2.4 cmake
https://cmake.org/download/

C:\Users\penghuishun.CRBCOA\AppData\Local\Apps

3.
All information below assumes C:\Users\penghuishun.CRBCOA\AppData\Local\Apps as the base directory, and
C:\Users\penghuishun.CRBCOA\AppData\Local\Apps\Tora as tora checkout.

 


2. All related steps are done in the "Visual Studio Command Prompt"

Download&Install binaries for MSVC
2a. set env variable QTDIR in MSVC command prompt
.


@ECHO OFF

set DEV1=D:\Qt\Qt5.7.1set QTDIR=%DE1V%set PATH=%SystemRoot%;%SystemRoot%32;%QTDIR%;

set PATH=%SystemRoot%;%SystemRoot%32;C:\Users\penghuishun.CRBCOA\AppData\Local\Apps\CMake\bin

echo Setting MSVC2010 Env.
set DEV=C:\Users\penghuishun.CRBCOA\AppData\Local\Apps\Common
set VSINSTALLDIR=%DEV%set VCINSTALLDIR=%DEV%set DevEnvDir=%VSINSTALLDIR%7\IDE
set PATH=%VCINSTALLDIR%;%VSINSTALLDIR%7\Tools;%VSINSTALLDIR%7\IDE;%VCINSTALLDIR%;%PATH%
set INCLUDE=%VCINSTALLDIR%;%INCLUDE%
set LIB=%VCINSTALLDIR%;%LIB%
set LIBPATH=%VCINSTALLDIR%

echo Env. ready.

================================================================================

11. Download and install cmake from www.cmake.org. Into D:\DEVEL (*without* spaces in the PATH

 

12. Check and set paths
- QTDIR
- CMAKE
- Doxygen (Optional)
- OpenSSL
- Nasm (Optional)
- Perl
- DirectX SDK (Optional)
- Windows SDK 7.1 (Optional)
- Tortoise SVN (svn.exe is needed while building)
- MSVC

 


14. Compile Tora in command prompt
mkdir d:\devel\tora3\debug
cd d:\devel\tora3\debug
cmake -DBOOST_ROOT=D:/DEVEL/boost_1_58_0 -DWANT_INTERNAL_QSCINTILLA=1 -DWANT_INTERNAL_LOKI=1 -DCMAKE_BUILD_TYPE=Debug -G "NMake Makefiles" ..

(测试失败,因为下载的不是安装qt,需要安装源代码版本,我们下载的是exe 版本,所以这次测试失败的,找不到mysql.pro)
nmake

######
How to Build the QMYSQL Plugin on Windows
You need to get the MySQL installation files. Run SETUP.EXE and choose "Custom Install". Install the "Libs & Include Files" Module. Build the plugin as follows (here it is assumed that MySQL is installed in C:\MySQL):

cd %QTDIR%\src\plugins\sqldrivers\mysql
qmake "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MYSQL\MySQL Server <version>\lib\opt\libmysql.lib" mysql.pro
nmake
######

https://blog.csdn.net/qq_39340204/article/details/78594854?locationNum=4&fps=1

 https://www.cnblogs.com/codingmylife/archive/2010/01/19/1678530.html

https://jingyan.baidu.com/article/27fa7326ffb99146f8271fe0.html

https://blog.csdn.net/gzshun/article/details/8493864

 

 

###

编译QT的MySql驱动问题及解决方案

 

      做毕业设计要用到MySql,界面方面想用下QT,顺便学习一下QT的使用。上去就碰到问题,没有MySql的驱动(其实在.\Qt\4.6.0\plugins\sqldrivers目录下有,后来编译完了才发现,这里要崩溃一下~)。GOOGLE了一下,翻了翻网页,就开始编译驱动了。

      这里使用QT4.6.0版本和VS2008自带的编译器

      使用的命令行参数是:

qmake –o Makefile INCLUDEPATH+="D:\Program Files\MySQL\MySQL Server 5.1\include" LIBS+="D:\Program Files\MySQL\MySQL Server 5.1\lib\opt\libmysql.lib" mysql.pro
nmake

      跟预料中的一样,编译出错,错误是"cannot find file: mysql.pro",费了半天劲终于发现我进入的目录是".\Qt\4.6.0\src\sql\drivers\mysql"而不是传说中的".\Qt\4.6.0\src\plugins\sqldrivers\mysql"(本目录才是正确路径!)。发生本错误的同志们一定要检查一下命令行的路径进的是否正确!

      一个问题解决了,qmake成功完成,开始nmake。这里先是碰到了qsqlmysqld_resource.rc中找不到"WinVer.h"的错误。找了找,发现WinVer.h头文件居然在Windows SDK的文件夹下,于是在".\Microsoft Visual Studio 9.0\Common7\Tools"中找到了vsvars32.bat设置环境变量的批处理,把该批处理拖入命令行窗口运行一遍(注意该批处理仅设置本次命令行窗口中的环境变量,并未修改注册表,所以每次打开个新命令行窗口都要运行一次批处理才可获得其中包含的环境变量设置!),再nmake,找不到WinVer.h的问题解决了。

      再次nmake,这次问题就诡异了,居然找不到"mysql.h"!但mysql.h已经在qmake的INCLUDEPATH参数中包含进去了,怎么可能找不到?郁闷,打开Makefile.Debug看看,发现里面INCLUDE进去的"D:\Program Files\MySQL\MySQL Server 5.1\include"每个空格处都被认为是一个路径,好好的路径给分的希碎,qmake的智商太低了!没法,把MySQL Server 5.1文件夹下的include和lib文件夹直接拷贝到根目录下,这样INCLUDEPATH和LIBS路径均无空格,再次qmake、nmake,OK了!

      总结:QT编译MySql驱动注意要点:

  1. 先检查".\Qt\4.6.0\plugins\sqldrivers"中有无sql驱动,有的话就别费这劲编译了!
  2. 安装MySql时要勾住“C Include Files 和 Lib Files”选项,这样才能装上MySql的头文件和链接库。
  3. 安装MySql时路径中不要有空格,不然编译驱动太费劲(上面的找不到"mysql.h"错误)。
  4. 命令行进行qmake和nmake前,一定要先转入正确目录(上面的"cannot find file: mysql.pro"错误)!
  5. 在nmake前最好运行一遍vsvars32.bat批处理(上面的找不到"WinVer.h"错误)。