Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QT mysql connectivity issue on other than default port



  • Hi,

    I have QT mysql connectivity issue.

    I have created one docker instance where I have installed mysql. This mysql instance is running
    on port 6603 and not a regular port of 3306.
    This port is open and is accessible from outside as well. Now I am connecting to this mysql instance
    from all other applications which is not built using QT, like I am able to connect using node js or
    any other 3rd party mysql editor. This means there is no connectivity issue.
    But when I try to connect to this server using QSqlDatabase, it is either not connecting or says access denied.
    However, if I change the above server port from 6603 to default 3306, QT application is able to connect.
    Not getting where the things are going wrong. I have used below code of QT.

    QJsonObject jo = getConnectionDetails(); // getConnectionDetails has all values of actual connections.
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL",jo.value("conn_name").toString());
    db.setHostName(jo.value("hostname").toString());
    db.setDatabaseName(jo.value("dbname").toString());
    db.setUserName(jo.value("username").toString());
    db.setPassword(jo.value("password").toString());
    db.setPort(jo.value("port").toInt());
    if (!db.open()){
            error = db.lastError().databaseText();
            qDebug() << "Connection error: " + error;
            return false;
        }
        return true;
    

    Above code is part of connector function.
    Please suggest why this happening?

    Cheers

    Manish


  • Lifetime Qt Champion

    @Manish-Bhavsar said in QT mysql connectivity issue on other than default port:

    jo.value("port").toInt()

    Did you actually check if it returns what you're expecting?


  • Lifetime Qt Champion

    Hi,

    Beside the port number.

    What exact error are you getting ?

    Do you have the MySQL plugins for your Qt installation ?
    How did you install Qt ?
    Which version is it ?
    On which OS ?


Log in to reply