[MySQL][ODBC 8.0(w) Driver] Can't connect to MySQL server on 'localhost' (10061) QODBC3: Unable to connect"

  • Hi!..

    I have installed a Windows computer having MariaDB installed, its ip is, now I'm trying to connect through another computer on the same LAN, the ODBC connector on Data Sources (Windows) test connection successfuly so driver is working fine...

    Tried this example to test the remote connection:

    int main(int argc, char *argv[])
        QCoreApplication a(argc, argv);
        QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3");
        db.setDatabaseName("Driver={MySQL ODBC 8.0 Unicode Driver};Database=db0");
        db.setPort(3306);                                     //Update: this has no effect
        db.setHostName("");   //Update: this has no effect
        if (!db.open()) qDebug() << db.lastError().text();
        else {
            qDebug() << "Success!";
        return a.exec();

    Output is:
    [MySQL][ODBC 8.0(w) Driver] Can't connect to MySQL server on 'localhost' (10061) QODBC3: Unable to connect"

    I'm a bit confused why is it claiming for localhost if I setup
    Any help?.. Thanks so much in advance.

    Update :
    I have noticed that setPort and setUserName had no effect, is more like those values are being overwritten from somewhere... that's why output points to localhost rather than server ip.... I say this because I have tested the same example on the server itself with loopback and worked, then changed the setHostName to (a random ip) and worked again.. ...

  • Lifetime Qt Champion


    I am by no means an ODBC expert but I think you have to pass that information through the connection string.

    See here.

    It's also explained in the Qt ODBC driver documentation.

  • you're absolutely right,... this is the string that worked for me:

    QString connection_string = 
    "Driver={MySQL ODBC 8.0 Unicode Driver};"
    "Server=, 3306;"


  • Lifetime Qt Champion

    Great !

    Then please mark the thread as solved so other forum members may know a solution has been found :-)

Log in to reply