Results 1 to 3 of 3

Thread: Problem with connecting to MySql using SSL

  1. #1
    Join Date
    Mar 2010
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem with connecting to MySql using SSL

    Hi,

    I am trying to connect MySql database using an SSL connection. Connecting without SSL works fine.

    I created a database and a user with REQUIRE SSL option. When I try to connect I get: "SSL connection error QMYSQL: Unable to connect".

    I am using Qt 4.7 64 bit on Ubuntu 10.04

    The code looks like the following:

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", m_connName);
    2. if (!db.isValid())
    3. {
    4. return;
    5. }
    6. db.setDatabaseName(dbName);
    7. db.setHostName("localhost");
    8. db.setPort(3306);
    9. db.setConnectOptions("CLIENT_SSL=1;CLIENT_IGNORE_SPACE=1");
    10. if (!db.open(userName, password))
    11. {
    12. qDebug()<<db.lastError().text();
    13. return;
    14. }
    To copy to clipboard, switch view to plain text mode 

    Was anyone able to work using this setup before?

    Thank you

  2. #2
    Join Date
    Mar 2008
    Posts
    16
    Thanks
    3
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Problem with connecting to MySql using SSL

    I guess you have to configure server to support SSL (SSL permission on account, ciphers, certificate,etc.). You can read more here http://dev.mysql.com/doc/refman/5.0/...nnections.html

  3. #3
    Join Date
    Mar 2010
    Location
    Belgium
    Posts
    14
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem with connecting to MySql using SSL

    In the other hand, client-side shoud be set up too :

    Qt Code:
    1. db.setConnectOptions("CLIENT_SSL=1;CLIENT_IGNORE_SPACE=1");
    2. QVariant v = db.driver()->handle();
    3. if (v.isValid() && qstrcmp(v.typeName(), "MYSQL*")==0)
    4. {
    5. MYSQL *handle = static_cast<MYSQL *>(v.data());
    6. if (handle != NULL)
    7. {
    8. mysql_ssl_set(handle, "./ssl/client-key.pem",
    9. "./ssl/client-cert.pem", "./ssl/cacert.pem",
    10. NULL, NULL);
    11. }
    12. }
    13. db.open();
    To copy to clipboard, switch view to plain text mode 

    Refer to mysql_ssl_set() for details.

Similar Threads

  1. Problem Wtih Connecting MySQL Database on Windows
    By dummystories in forum Installation and Deployment
    Replies: 25
    Last Post: 29th April 2009, 11:12
  2. connecting MySQL remotely
    By rickym in forum Qt Programming
    Replies: 5
    Last Post: 25th March 2007, 09:55
  3. Crash while connecting to MySQL
    By vfernandez in forum Qt Programming
    Replies: 1
    Last Post: 9th January 2007, 13:05
  4. connecting to MySQL through it's API
    By Philip_Anselmo in forum Installation and Deployment
    Replies: 20
    Last Post: 30th May 2006, 23:22
  5. Error connecting to MySQL
    By probine in forum Qt Programming
    Replies: 20
    Last Post: 23rd February 2006, 23:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.