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 '192.168.1.7' (107) QMYSQL: Unable to connect
    

    MySQLClient.pro

    QT       += core gui sql
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = MySQLClient
    TEMPLATE = app
    DEFINES += QT_DEPRECATED_WARNINGS
    
    SOURCES += \
            main.cpp \
            mainwindow.cpp
    
    HEADERS += \
            mainwindow.h
    
    FORMS += \
            mainwindow.ui
    
    CONFIG += mobility
    MOBILITY = 
    
    DISTFILES += \
        android/AndroidManifest.xml \
        android/gradle/wrapper/gradle-wrapper.jar \
        android/gradlew \
        android/res/values/libs.xml \
        android/build.gradle \
        android/gradle/wrapper/gradle-wrapper.properties \
        android/gradlew.bat
    
    ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
    
    contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
        ANDROID_EXTRA_LIBS = \
            /home/mbnoimi/Scripts/Shell/mysql_driver_qt/mariadb-connector-c-2.3.2-src/build/libmariadb/libmariadb.so \
            $$PWD/../../../../.Qt/5.9.1/android_armv7/plugins/sqldrivers/libqsqlmysql.so
    }
    

    Connection snippet:

        _db = QSqlDatabase::addDatabase("QMYSQL");
        _db.setHostName("192.168.1.7");
        _db.setPort("3306");
        _db.setDatabaseName("db_account_76603915");
        _db.setUserName("jassem");
        _db.setPassword("123654789");
        if (!_db.open()) {
            ui->textEdit->append(_db.lastError().text());
        } 
    

    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

    Hi,

    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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.