PDA

View Full Version : QSqlDatabase connection error in QT(Mac) QSqlError-2049, QMYSQL: Unable to connect



ejoshva
16th February 2015, 06:08
Hi,
I am getting an error on executing the below line in QT in MAC. Have installed mysql 5.6.23
The code is as below
m_drivername = "QMYSQL3";
ondb = QSqlDatabase::addDatabase(m_drivername);
When control reaches this line getting the below warning
QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.

ondb.setHostName(m_hostName);
ondb.setDatabaseName(m_databasename);
ondb.setUserName(m_database_username);
ondb.setPassword(m_database_password);
if(!ondb.open())
{
qDebug()<<ondb.lastError();
}

lastError() prints ==> QSqlError("2049", "QMYSQL: Unable to connect", "Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)")

Kindly help to resolve this issue in QT in Mac

wysota
16th February 2015, 06:48
Your version of the database engine cannot talk using MySQL 3 protocol. Use QMYSQL driver instead.

ejoshva
16th February 2015, 07:05
I tried making use of "MYSQL" still the same.

wysota
16th February 2015, 07:16
http://dev.mysql.com/doc/refman/5.0/en/old-client.html

ejoshva
16th February 2015, 09:10
I am able to connect into mysql without any issues.
Below are lines which were got on connecting to mysql
DTPC-184N:mysql-5.6.23-osx10.8-x86_64 user$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.23 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

ejoshva
17th February 2015, 09:25
After installing mysql 5.6 in mac 10.9.5

When I try to run the below lines..
cd $QTDIR/src/plugins/sqldrivers/mysql
qmake "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro
make
getting error as below
TPC-184N:mysql user$ qmake "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro
WARNING: /Applications/QT/5.4/Src/qtbase/src/plugins/sqldrivers/qsqldriverbase.pri:4: Unable to find file for inclusion qt_plugin
Project MESSAGE: Warning: unknown QT: core-private
Project MESSAGE: Warning: unknown QT: sql-private
Project MESSAGE: qtAddLibrary: found framework QtCore in directory /opt/local/Library/Frameworks
Failure to open file: /Applications/QT/5.4/Src/qtbase/src/plugins/sqldrivers/mysql/Makefile
Unable to generate makefile for: mysql.pro
DTPC-184N:mysql user$

wysota
17th February 2015, 11:32
Didn't you already have a mysql plugin? Why are you rebuilding it?

ejoshva
17th February 2015, 11:45
Do I already have. I dont get it.
How can I check whether its already present.

Added after 4 minutes:

ondb = QSqlDatabase::addDatabase(m_drivername);
ondb.setHostName(m_hostName);
ondb.setDatabaseName(m_databasename);
ondb.setUserName(m_database_username);
ondb.setPassword(m_database_password);
if(!ondb.open())
{
qDebug() << ondb.lastError();
}
the below error is thrown, that why I am trying to do that qmake.
QSqlError("2049", "QMYSQL: Unable to connect", "Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)")

wysota
17th February 2015, 12:25
Do I already have. I dont get it.
How can I check whether its already present.

sqldrivers directory of your Qt installation will contain files with "mysql" in their name (e.g. libqmysql.so or adequate dylib).

ejoshva
17th February 2015, 12:42
Yes I have all the files.
so you mean to say that plugin is already created.

but still I am not able to connect to db through code.

getting the error on checking ondb.lastError()
QSqlError("2049", "QMYSQL: Unable to connect", "Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)")
I am able to connect to the db through mysql workbench

please guide me to get rid of this issue.

wysota
17th February 2015, 12:50
Yes I have all the files.
so you mean to say that plugin is already created.

but still I am not able to connect to db through code.

getting the error on checking ondb.lastError()
QSqlError("2049", "QMYSQL: Unable to connect", "Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)")
I am able to connect to the db through mysql workbench

please guide me to get rid of this issue.

I already gave you a link to the site describing the problem. Your problem is not in Qt but in a connection between your client library and server. Make sure your client (your app) uses a client library (libmysqlclient) which is compatible with your server and that they talk using a proper protocol.

ejoshva
18th February 2015, 04:31
I did follow all the steps provided in that link. But still no success. :(

wysota
18th February 2015, 08:41
I did follow all the steps provided in that link. But still no success. :(

Then try googling for other info. Without sitting in front of your computer we wouldn't be able to help anyway. Make sure your application is using the client library you think it is using.