Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Cannot conect to MySql server
Forum Updated to NodeBB v4.3 + New Features

Cannot conect to MySql server

Scheduled Pinned Locked Moved Solved General and Desktop
qtsqlcmakeubuntu
5 Posts 3 Posters 818 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fnoefen
    wrote on 8 Nov 2021, 16:04 last edited by
    #1

    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?

    J 1 Reply Last reply 8 Nov 2021, 16:23
    0
    • F fnoefen
      8 Nov 2021, 16:04

      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?

      J Offline
      J Offline
      JonB
      wrote on 8 Nov 2021, 16:23 last edited by
      #2

      @fnoefen
      Is this actually an error or just a message? Does your db.open() succeed? It sounds like a MySQL issue, how did you install/configure that?

      1 Reply Last reply
      1
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 8 Nov 2021, 16:26 last edited by
        #3

        What exact Qt version do you use?
        You should actually check if db.open() succeeds as @JonB already said.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fnoefen
          wrote on 8 Nov 2021, 16:43 last edited by
          #4

          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 :)

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 8 Nov 2021, 17:27 last edited by
            #5

            I was asking for the exact Qt version because of this: https://bugreports.qt.io/browse/QTBUG-97054

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            2

            3/5

            8 Nov 2021, 16:26

            • Login

            • Login or register to search.
            3 out of 5
            • First post
              3/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved