error connecting to mysql with ssl connect options
-
Qt: 5.13.0
OS: Linux 64 bitsql 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 toomy 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)")
-
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 strangeQSqlDatabase 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 :)
-
Qt: 5.13.0
OS: Linux 64 bitsql 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 toomy 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)")
-
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 strangeQSqlDatabase 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 :)