MySQL driver isn't installed
-
wrote on 9 Feb 2022, 22:35 last edited by pierrbt 2 Sept 2022, 22:40
Hi,
I have installed a MySQL server on my computer few days ago and I'm actually trying to connect my application to that database. I tried to connect it but i saw that the QMySQL database type wasnt' installed. I tried to reinstall the "Connector C++" from MySQL website and tried some manipulations to make that function worked but it still doesn't work.Here is my code, hope you can solve my problem :
QSqlDatabase Register::SQLConnection() { qDebug() << QSqlDatabase::drivers(); if(!db.isValid()) { db = QSqlDatabase::addDatabase("QSQLITE"); db.setHostName("localhost"); db.setPort(3306); db.setDatabaseName("mysteriousdb"); db.setUserName("root"); db.setPassword("whoknows"); QString opts = "QF_CODEC_NAME=cp1250;QF_MYSQL_SET_NAMES=latin1"; qDebug() << "Connecting to " << db.connectionName() << " at " << db.hostName() << "on the port " << db.port() << " as " << db.userName(); db.setConnectOptions(opts); bool ok = db.open(); qDebug() << db.driver(); if(!ok) qCritical() << "ERROR open database:" << db.lastError().text(); else { qDebug() << "Connect successful"; QSqlQuery query = QSqlQuery(db); QString sql; sql += "SELECT * FROM users;"; query.prepare(sql); qDebug() << query.exec(); query.clear(); } } return db; }
pierrbt.
Edit : I used QSQLITE to test if it was working but it doesn't, and here is the Application Output :
QList("QSQLITE", "QODBC", "QPSQL") Connecting to "qt_sql_default_connection" at "localhost" on the port 3306 as "root" QSQLiteDriver(0x1d01f214a20) Connect successful false
-
wrote on 10 Feb 2022, 23:42 last edited by
@jsulm I finally fix my problem, I replaced lots of DLLs of the MySQL and MinGW folders using that repository and it finally work ! The MySQL Driver is detected by the compiler and I can perfectly use it. I tried to made that command :
INSERT INTO users (pseudo, mail, birthdate, passwd) VALUES ("pierrbt", "haha@gmail.com", "2000-01-01", "testPassword");
and it's working. Thanks for helping me to fix that problem.
-
Hi,
I have installed a MySQL server on my computer few days ago and I'm actually trying to connect my application to that database. I tried to connect it but i saw that the QMySQL database type wasnt' installed. I tried to reinstall the "Connector C++" from MySQL website and tried some manipulations to make that function worked but it still doesn't work.Here is my code, hope you can solve my problem :
QSqlDatabase Register::SQLConnection() { qDebug() << QSqlDatabase::drivers(); if(!db.isValid()) { db = QSqlDatabase::addDatabase("QSQLITE"); db.setHostName("localhost"); db.setPort(3306); db.setDatabaseName("mysteriousdb"); db.setUserName("root"); db.setPassword("whoknows"); QString opts = "QF_CODEC_NAME=cp1250;QF_MYSQL_SET_NAMES=latin1"; qDebug() << "Connecting to " << db.connectionName() << " at " << db.hostName() << "on the port " << db.port() << " as " << db.userName(); db.setConnectOptions(opts); bool ok = db.open(); qDebug() << db.driver(); if(!ok) qCritical() << "ERROR open database:" << db.lastError().text(); else { qDebug() << "Connect successful"; QSqlQuery query = QSqlQuery(db); QString sql; sql += "SELECT * FROM users;"; query.prepare(sql); qDebug() << query.exec(); query.clear(); } } return db; }
pierrbt.
Edit : I used QSQLITE to test if it was working but it doesn't, and here is the Application Output :
QList("QSQLITE", "QODBC", "QPSQL") Connecting to "qt_sql_default_connection" at "localhost" on the port 3306 as "root" QSQLiteDriver(0x1d01f214a20) Connect successful false
@pierrbt said in MySQL driver isn't installed:
QList("QSQLITE", "QODBC", "QPSQL")
You do not have Qt MySQL plug-in installed.
This plug-in is not delivered by default, you have to build it by yourself, see https://doc.qt.io/qt-5/sql-driver.html -
Hi,
I have installed a MySQL server on my computer few days ago and I'm actually trying to connect my application to that database. I tried to connect it but i saw that the QMySQL database type wasnt' installed. I tried to reinstall the "Connector C++" from MySQL website and tried some manipulations to make that function worked but it still doesn't work.Here is my code, hope you can solve my problem :
QSqlDatabase Register::SQLConnection() { qDebug() << QSqlDatabase::drivers(); if(!db.isValid()) { db = QSqlDatabase::addDatabase("QSQLITE"); db.setHostName("localhost"); db.setPort(3306); db.setDatabaseName("mysteriousdb"); db.setUserName("root"); db.setPassword("whoknows"); QString opts = "QF_CODEC_NAME=cp1250;QF_MYSQL_SET_NAMES=latin1"; qDebug() << "Connecting to " << db.connectionName() << " at " << db.hostName() << "on the port " << db.port() << " as " << db.userName(); db.setConnectOptions(opts); bool ok = db.open(); qDebug() << db.driver(); if(!ok) qCritical() << "ERROR open database:" << db.lastError().text(); else { qDebug() << "Connect successful"; QSqlQuery query = QSqlQuery(db); QString sql; sql += "SELECT * FROM users;"; query.prepare(sql); qDebug() << query.exec(); query.clear(); } } return db; }
pierrbt.
Edit : I used QSQLITE to test if it was working but it doesn't, and here is the Application Output :
QList("QSQLITE", "QODBC", "QPSQL") Connecting to "qt_sql_default_connection" at "localhost" on the port 3306 as "root" QSQLiteDriver(0x1d01f214a20) Connect successful false
wrote on 10 Feb 2022, 08:19 last edited by@pierrbt
If you are asking about QMYSQL plug-in then you must follow @jsulm's advice.If you are asking why your code shown using SQLite/
QSQLITE
appears to returnfalse
fromquery.exec("SELECT * FROM users;")
there is a QSqlError QSqlQuery::lastError() const to call after theexec()
. Maybe your database does not have anyusers
table? -
@pierrbt
If you are asking about QMYSQL plug-in then you must follow @jsulm's advice.If you are asking why your code shown using SQLite/
QSQLITE
appears to returnfalse
fromquery.exec("SELECT * FROM users;")
there is a QSqlError QSqlQuery::lastError() const to call after theexec()
. Maybe your database does not have anyusers
table? -
@pierrbt
If you are asking about QMYSQL plug-in then you must follow @jsulm's advice.If you are asking why your code shown using SQLite/
QSQLITE
appears to returnfalse
fromquery.exec("SELECT * FROM users;")
there is a QSqlError QSqlQuery::lastError() const to call after theexec()
. Maybe your database does not have anyusers
table?wrote on 10 Feb 2022, 10:14 last edited by pierrbt 2 Oct 2022, 10:15 -
@pierrbt said in MySQL driver isn't installed:
I configured the plugin as a SQLite one, and the users table exists because i tried the same command in the main MySQL shell and it was working
But did you create that table in your SQLite database?
-
wrote on 10 Feb 2022, 10:48 last edited by JonB 2 Oct 2022, 10:49
@JonB said in MySQL driver isn't installed:
there is a
QSqlError QSqlQuery::lastError() const
to call after theexec()
.? What's the point of guessing if you have a call to use?
-
wrote on 10 Feb 2022, 14:44 last edited by
@jsulm I use a MySQL database and, yes i create it. And, it may seem like an obvious question but in the doc you send me, they said to execute a command, so i run that command on the Windows Command Prompt but it return an error :
C:\Qt\6.2.3\Src>configure.bat -sql-mysql -- -DMySQL_INCLUDE_DIR="C:\Program Files\MySQL\MySQL Connector C 6.1\include" -DMySQL_LIBRARY="C:\Program Files\MySQL \MySQL Connector C 6.1\lib\libmysql.lib +qtbase cd + C:\Qt\6.2.3\Src\qtbase\configure.bat -top-level -sql-mysql -- -DMySQL_INCLUDE_DIR="C:\Program Files\MySQL\MySQL Connector C 6.1\include" -DMySQL_LIBRARY=" C:\Program Files\MySQL\MySQL Connector C 6.1\lib\libmysql.lib -top-level -sql-mysql -- -DMySQL_INCLUDE_DIR="C:\Program Files\MySQL\MySQL Connector C 6.1\include" -DMySQL_LIBRARY="C:\Program Files\MySQL\MySQL Connector C 6.1\lib\libmysql. lib>config.opt.in 'cmake' is not recognized as an internal command or external, an executable program or a batch file. 'cmake' is not recognized as an internal command or external, an executable program or a batch file.
And btw, here is the MySQL table config :
-
@jsulm I use a MySQL database and, yes i create it. And, it may seem like an obvious question but in the doc you send me, they said to execute a command, so i run that command on the Windows Command Prompt but it return an error :
C:\Qt\6.2.3\Src>configure.bat -sql-mysql -- -DMySQL_INCLUDE_DIR="C:\Program Files\MySQL\MySQL Connector C 6.1\include" -DMySQL_LIBRARY="C:\Program Files\MySQL \MySQL Connector C 6.1\lib\libmysql.lib +qtbase cd + C:\Qt\6.2.3\Src\qtbase\configure.bat -top-level -sql-mysql -- -DMySQL_INCLUDE_DIR="C:\Program Files\MySQL\MySQL Connector C 6.1\include" -DMySQL_LIBRARY=" C:\Program Files\MySQL\MySQL Connector C 6.1\lib\libmysql.lib -top-level -sql-mysql -- -DMySQL_INCLUDE_DIR="C:\Program Files\MySQL\MySQL Connector C 6.1\include" -DMySQL_LIBRARY="C:\Program Files\MySQL\MySQL Connector C 6.1\lib\libmysql. lib>config.opt.in 'cmake' is not recognized as an internal command or external, an executable program or a batch file. 'cmake' is not recognized as an internal command or external, an executable program or a batch file.
And btw, here is the MySQL table config :
@pierrbt said in MySQL driver isn't installed:
'cmake' is not recognized as an internal command
You need cmake to build Qt6.
And I was refering to:
"I configured the plugin as a SQLite one, and the users table exists because i tried the same command in the main MySQL shell and it was working".
SQLite != MySQL
SQLite stores the database in a file, it has absolutelly nothing to do with MySQL. -
wrote on 10 Feb 2022, 14:58 last edited by
-
I've already installed CMake :
but it don't appear in the build options, have i need to build from a command prompt ?
And yes i know that MySQL != SQLite but i was just trying to test ...
@pierrbt Make sure folder containing cmake executable is in path.
On Windows you also should execute batch script which prepares the build environment (it should be in the Qt start menu entry and in Qt installation folder). Which one depends on your compiler: either the one for MinGW or MSVC. -
@pierrbt Make sure folder containing cmake executable is in path.
On Windows you also should execute batch script which prepares the build environment (it should be in the Qt start menu entry and in Qt installation folder). Which one depends on your compiler: either the one for MinGW or MSVC.wrote on 10 Feb 2022, 15:09 last edited by pierrbt 2 Oct 2022, 15:12 -
@pierrbt said in MySQL driver isn't installed:
And by the way, which compiler should i use, MSVC, MinGW or WebAssembly @jsulm ?
That's up to you.
WebAssembly is for applications running in a browser. -
wrote on 10 Feb 2022, 23:42 last edited by
@jsulm I finally fix my problem, I replaced lots of DLLs of the MySQL and MinGW folders using that repository and it finally work ! The MySQL Driver is detected by the compiler and I can perfectly use it. I tried to made that command :
INSERT INTO users (pseudo, mail, birthdate, passwd) VALUES ("pierrbt", "haha@gmail.com", "2000-01-01", "testPassword");
and it's working. Thanks for helping me to fix that problem.
1/15