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. error connecting to mysql with ssl connect options
QtWS25 Last Chance

error connecting to mysql with ssl connect options

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.8k 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.
  • V Offline
    V Offline
    Virgo
    wrote on last edited by Virgo
    #1

    Qt: 5.13.0
    OS: Linux 64 bit

    sql query to create test accounts

    create user
    'native'@'localhost' identified with mysql_native_password by 'password',
    'sha256'@'localhost' identified with sha256_password by 'password'
    require ssl;
    

    and this is how i compiled qt's mysql plugin
    source i used: qtbase-everywhere-src-5.13.0.tar.xz
    commands:

    ./configure -opensource -confirm-license -release -sql-mysql
    cd src/plugins/sqldrivers
    qmake
    make sub-mysql
    

    everything worked fine and i didnt see any error or warming

    connecting to non-ssl-required mysql account is just fine, but fails connecting to ssl-required ones
    the mysql client works fine too

    my test c++ code:

    #include <QCoreApplication>
    #include <QtSql>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
        db.setConnectOptions("SSL_KEY=client-key.pem;SSL_CERT=client-cert.pem;SSL_CA=ca.pem;SSL_CIPHER=TLS_AES_256_GCM_SHA384");
        //db.setUserName("native");
        db.setUserName("sha256");
        db.setPassword("password");
        qDebug()<< db.open();
        qDebug()<< db.lastError();
        return a.exec();
    }
    

    output of the program is just like this

    false
    QSqlError("1045", "QMYSQL: Unable to connect", "Access denied for user 'sha256'@'localhost' (using password: YES)")
    
    Pablo J. RoginaP 1 Reply Last reply
    0
    • V Offline
      V Offline
      Virgo
      wrote on last edited by Virgo
      #3

      yes im able to login using

      mysql -h localhost -u sha256 -p --ssl-mode=required
      

      i happened to fine a fix for it
      just need to tell QSqlDatabase an ip address to connect to instead of the default host name or the "localhost"

      db.setHostName("localhost"); // doesnt work
      db.setHostName("127.0.0.1"); // works
      db.setHostName("::1"); // works
      

      still not sure what the problem actually is

      thanks for the answer anyway

      edit:
      but its really strange

      QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
      //db.setConnectOptions("SSL_KEY=client-key.pem;SSL_CERT=client-cert.pem;SSL_CA=ca.pem");
      db.setHostName("::1");
      db.setUserName("sha256");
      db.setPassword("password");
      qDebug()<< db.open();
      qDebug()<< db.lastError();
      

      the setConnectOptions() here can be omitted and it will still connect :)

      1 Reply Last reply
      1
      • V Virgo

        Qt: 5.13.0
        OS: Linux 64 bit

        sql query to create test accounts

        create user
        'native'@'localhost' identified with mysql_native_password by 'password',
        'sha256'@'localhost' identified with sha256_password by 'password'
        require ssl;
        

        and this is how i compiled qt's mysql plugin
        source i used: qtbase-everywhere-src-5.13.0.tar.xz
        commands:

        ./configure -opensource -confirm-license -release -sql-mysql
        cd src/plugins/sqldrivers
        qmake
        make sub-mysql
        

        everything worked fine and i didnt see any error or warming

        connecting to non-ssl-required mysql account is just fine, but fails connecting to ssl-required ones
        the mysql client works fine too

        my test c++ code:

        #include <QCoreApplication>
        #include <QtSql>
        
        int main(int argc, char *argv[])
        {
            QCoreApplication a(argc, argv);
            QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
            db.setConnectOptions("SSL_KEY=client-key.pem;SSL_CERT=client-cert.pem;SSL_CA=ca.pem;SSL_CIPHER=TLS_AES_256_GCM_SHA384");
            //db.setUserName("native");
            db.setUserName("sha256");
            db.setPassword("password");
            qDebug()<< db.open();
            qDebug()<< db.lastError();
            return a.exec();
        }
        

        output of the program is just like this

        false
        QSqlError("1045", "QMYSQL: Unable to connect", "Access denied for user 'sha256'@'localhost' (using password: YES)")
        
        Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #2

        @virgo long time I don't work with MySql but I remember that under some settings, access from localhost was disabled.

        So are you able to connect to the DB from same location with some other tool, i.e. command line? You may want to check this answer just in case

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        1
        • V Offline
          V Offline
          Virgo
          wrote on last edited by Virgo
          #3

          yes im able to login using

          mysql -h localhost -u sha256 -p --ssl-mode=required
          

          i happened to fine a fix for it
          just need to tell QSqlDatabase an ip address to connect to instead of the default host name or the "localhost"

          db.setHostName("localhost"); // doesnt work
          db.setHostName("127.0.0.1"); // works
          db.setHostName("::1"); // works
          

          still not sure what the problem actually is

          thanks for the answer anyway

          edit:
          but its really strange

          QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
          //db.setConnectOptions("SSL_KEY=client-key.pem;SSL_CERT=client-cert.pem;SSL_CA=ca.pem");
          db.setHostName("::1");
          db.setUserName("sha256");
          db.setPassword("password");
          qDebug()<< db.open();
          qDebug()<< db.lastError();
          

          the setConnectOptions() here can be omitted and it will still connect :)

          1 Reply Last reply
          1

          • Login

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