Important: Please read the Qt Code of Conduct -

Unable to connect to MySQL

  • Hi,

    Using this Gist I could build MySQL plugin but unfortunately I unable to connect to any MySQL server.

    May you please help me to find out where is the problem?

    I'm using:

    • Qt 5.9.1
    • Qt Creator 4.3.1
    • Linux Mint 18.2 x64 xfce
    • Android API - 19

    Error message (produced by QSqlDatabase::lastError()):

    Can't connect to MySQL server on '' (107) QMYSQL: Unable to connect

    QT       += core gui sql
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = MySQLClient
    TEMPLATE = app
    SOURCES += \
            main.cpp \
    HEADERS += \
    FORMS += \
    CONFIG += mobility
    DISTFILES += \
        android/AndroidManifest.xml \
        android/gradle/wrapper/gradle-wrapper.jar \
        android/gradlew \
        android/res/values/libs.xml \
        android/build.gradle \
        android/gradle/wrapper/ \
    contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
            /home/mbnoimi/Scripts/Shell/mysql_driver_qt/mariadb-connector-c-2.3.2-src/build/libmariadb/ \

    Connection snippet:

        _db = QSqlDatabase::addDatabase("QMYSQL");
        if (! {

    IMPORTANT: I can connect to MySQL server through MySQL WorkBench using same parameters without any problem.

  • BTW, I posted this thread because I'm not sure what if this issue occurs because of corrupted QMYSQL driver or something else.

  • Lifetime Qt Champion


    Does your database accept connections from an external device for that account ?

    Also, don't forget to use a secure channel since you are on a different machine.

  • Thank you @SGaist

    Does your database accept connections from an external device for that account ?

    Yes, it accepts external connections without any problem.

    I discovered something new
    My app works fine in real devices while doesn't from AVD. I think this issue related to Android Emulator!
    I'll try find out what's going on and if you've any idea about this issue please post it.

Log in to reply