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. SSL connection error: unknown error number QMYSQL: Unable to connect
QtWS25 Last Chance

SSL connection error: unknown error number QMYSQL: Unable to connect

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 879 Views
  • 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.
  • A Offline
    A Offline
    Aditya20
    wrote on last edited by
    #1

    I am new to QT development. I am trying to connect with mysql database from the qt application but getting ssl connection error. Below is the code snippet.

    #include <QCoreApplication>
    #include <QSqlDatabase>
    #include <QSqlQuery>
    #include <QSqlError>
    #include <QDebug>

    void connectToDatabase() {
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setDatabaseName("aditya");
    db.setUserName("root");
    db.setPassword("aditya");
    db.setPort(3306);

    if (!db.open()) {
        qDebug() << "Error: connection with database fail:" << db.lastError().text();
    } else {
        qDebug() << "Database: connection ok";
    }
    

    }

    void executeQuery() {
    QSqlQuery query;
    if (query.exec("SELECT * FROM Test")) {
    while (query.next()) {
    QString name = query.value("name").toString();
    qDebug() << "Name:" << name;
    }
    } else {
    qDebug() << "Query failed:" << query.lastError().text();
    }
    }

    int main(int argc, char *argv[]) {
    QCoreApplication a(argc, argv);

    connectToDatabase();
    //executeQuery();
    
    return a.exec();
    

    }

    Getting below error while running the program

    Error: connection with database fail: "SSL connection error: unknown error number QMYSQL: Unable to connect"

    Any leads will be appreciated.

    Thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What kind of certificate are you using for that database ?
      Which version of Qt are you using ?
      On which OS ?
      Which version of MySQL ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        What kind of certificate are you using for that database ?
        Which version of Qt are you using ?
        On which OS ?
        Which version of MySQL ?

        A Offline
        A Offline
        Aditya20
        wrote on last edited by
        #3

        @SGaist I do not have any certificate added as of now.
        QT version: 6.5.6
        OS: Windows
        MySQL version: 8.0.36

        A 1 Reply Last reply
        0
        • A Aditya20

          @SGaist I do not have any certificate added as of now.
          QT version: 6.5.6
          OS: Windows
          MySQL version: 8.0.36

          A Offline
          A Offline
          Aditya20
          wrote on last edited by
          #4

          @Aditya20 said in SSL connection error: unknown error number QMYSQL: Unable to connect:

          6.5.6

          6.5.3

          Christian EhrlicherC 1 Reply Last reply
          0
          • A Aditya20

            @Aditya20 said in SSL connection error: unknown error number QMYSQL: Unable to connect:

            6.5.6

            6.5.3

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Disable ssl on your mysql server and/or try to disable them with the appropriate connect options (but might not work when the mysql server is configured to not allow unencrypted connections).

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

            A 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              Disable ssl on your mysql server and/or try to disable them with the appropriate connect options (but might not work when the mysql server is configured to not allow unencrypted connections).

              A Offline
              A Offline
              Aditya20
              wrote on last edited by
              #6

              @Christian-Ehrlicher I have already disabled SSL on MySQL server mysql.png

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Aditya20
                wrote on last edited by
                #7

                I am still facing same issue. Any help would be appreciated

                JonBJ Christian EhrlicherC 2 Replies Last reply
                0
                • A Aditya20

                  I am still facing same issue. Any help would be appreciated

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @Aditya20
                  I don't know what it will tell us, but to start out can you connect successfully using, say, MySQL Workbench and mysqldump?

                  1 Reply Last reply
                  0
                  • A Aditya20

                    I am still facing same issue. Any help would be appreciated

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Aditya20 said in SSL connection error: unknown error number QMYSQL: Unable to connect:

                    I am still facing same issue. Any help would be appreciated

                    And you still did not played around with the corresponding connect options ... so no help from my side possible.

                    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
                    • A Offline
                      A Offline
                      Aditya20
                      wrote on last edited by
                      #10

                      @SGaist Any updates from your end for the issue

                      SGaistS 1 Reply Last reply
                      0
                      • A Aditya20

                        @SGaist Any updates from your end for the issue

                        SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @Aditya20 did you do the checks suggested by @JonB ?
                        Are you sure about the port ?
                        Are you sure that connections to that port are allowed ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        A 1 Reply Last reply
                        0
                        • SGaistS SGaist

                          @Aditya20 did you do the checks suggested by @JonB ?
                          Are you sure about the port ?
                          Are you sure that connections to that port are allowed ?

                          A Offline
                          A Offline
                          Aditya20
                          wrote on last edited by
                          #12

                          @SGaist I was finally able to resolve the issue by using skip_ssl in my.ini file.

                          1 Reply Last reply
                          0
                          • A Aditya20 has marked this topic as solved on

                          • Login

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