Cannot conect to MySql server
-
Hey, im trying to connect to an sql server but i keep getting this error:
MySQL: Unable to set the client character set to utf8 (""). Using 'utf8mb3' instead.
i do not think its a problem with finding the database, because if i change the name i get this error instead:
MySQL: Unable to set the client character set to utf8 ("Unknown database 'MyDatabase2'"). Using 'utf8mb3' instead.
also, im on Ubuntu, if that matters.
main.cpp:
#include <iostream> #include <QtSql> #include <QSqlDatabase> int main() { QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("localhost"); db.setUserName("MyUser"); db.setPassword("MyPassword"); db.setDatabaseName("MyDatabase"); db.open(); return 0; }
CMakeLists.txt:
cmake_minimum_required(VERSION 3.5) project(sqlProjekt LANGUAGES CXX) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 COMPONENTS Sql REQUIRED) add_executable(sqlProjekt main.cpp) target_link_libraries(sqlProjekt PRIVATE Qt6::Sql)
can you please help me?
-
What exact Qt version do you use?
You should actually check if db.open() succeeds as @JonB already said. -
weather or not its an error im not sure, it's colored red in the output, so i just assumed it was.
but checking the qt version was a great idea as i am apparently not using qt 6 but 5, and changing that in my cakelist seems to have fixed the issue.
Thanks for making me realise my stupid mistake :) -
I was asking for the exact Qt version because of this: https://bugreports.qt.io/browse/QTBUG-97054