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

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

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 901 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 19 Apr 2024, 10:42 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 19 Apr 2024, 21:41 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 20 Apr 2024, 06:18
      0
      • S SGaist
        19 Apr 2024, 21:41

        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 20 Apr 2024, 06:18 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 20 Apr 2024, 06:46
        0
        • A Aditya20
          20 Apr 2024, 06:18

          @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 20 Apr 2024, 06:46 last edited by
          #4

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

          6.5.6

          6.5.3

          C 1 Reply Last reply 20 Apr 2024, 07:05
          0
          • A Aditya20
            20 Apr 2024, 06:46

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

            6.5.6

            6.5.3

            C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 20 Apr 2024, 07:05 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 20 Apr 2024, 07:22
            0
            • C Christian Ehrlicher
              20 Apr 2024, 07:05

              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 20 Apr 2024, 07:22 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 25 Apr 2024, 08:29 last edited by
                #7

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

                J C 2 Replies Last reply 25 Apr 2024, 08:34
                0
                • A Aditya20
                  25 Apr 2024, 08:29

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

                  J Offline
                  J Offline
                  JonB
                  wrote on 25 Apr 2024, 08:34 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
                    25 Apr 2024, 08:29

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

                    C Offline
                    C Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 25 Apr 2024, 08:37 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 25 Apr 2024, 10:03 last edited by
                      #10

                      @SGaist Any updates from your end for the issue

                      S 1 Reply Last reply 25 Apr 2024, 20:25
                      0
                      • A Aditya20
                        25 Apr 2024, 10:03

                        @SGaist Any updates from your end for the issue

                        S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 25 Apr 2024, 20:25 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 26 Apr 2024, 06:25
                        0
                        • S SGaist
                          25 Apr 2024, 20:25

                          @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 26 Apr 2024, 06:25 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 26 Apr 2024, 06:25

                          10/12

                          25 Apr 2024, 10:03

                          • Login

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