remote mysql database connection



  • im almost 100% sure this has got to be documented, or has been asked, but i'm not finding a solution to my particular error. im attempting to connect from a windows machine to a linux server on the same LAN. I have everything included, and my DB connection code looks something like:

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
        db.setHostName("xxx.xxx.xxx.xxx");//<-remote IP
        db.setDatabaseName("database_name");
        db.setUserName("user");
        db.setPassword("password");
        if(!db.open()){
            qDebug() << db.isValid();
            qDebug() << "database not opened";
            qDebug() << db.lastError().text();
        }
    

    everything seems to check out, until the connection opens. it looks like it is defaulting to localhost. ive checked on the remote server, and the my.cnf file does not bind to localhost. the console returns:

    true
    database not opened
    "Access denied for user 'user'@'xxx.xxx.xxx.xxx' (using password: YES) QMYSQL: Unable to connect"
    

    what am i missing? i am using the same credentials that our webserver uses to connect to the database with no problems


  • Qt Champions 2016

    @mahbad
    Do it work on localhost ? ( as in locally)

    Could be the MYSQL plugin.

    Did you compile your own mysql plugin ? ( for windows)
    http://seppemagiels.com/blog/create-mysql-driver-qt5-windows



  • thanks @mrjj
    it does connect successfully if i run a mysql DB on local host and provide the same connection settings.
    I did not compile my own mysql plugin for windows. I have tried in the past and it always catches errors. I've installed fresh mysql files from their site, new qt creator with qt 5.9, and let qt install a fresh mingw compiler. when i execute mingw32-make.exe it spits out

    g++: error: %mysql%\lib\libmysql.lib: No such file or directory
    Makefile.Release:68: recipe for target '..\..\..\..\plugins\sqldrivers\qsqlmysql.dll' failed
    mingw32-make[1]: *** [..\..\..\..\plugins\sqldrivers\qsqlmysql.dll] Error 1
    mingw32-make[1]: Leaving directory 'C:/Qt/5.9/Src/qtbase/src/plugins/sqldrivers/mysql'
    Makefile:41: recipe for target 'release-all' failed
    mingw32-make: *** [release-all] Error 2
    

    but that lib file is indeed there


  • Qt Champions 2016

    @mahbad said in remote mysql database connection:

    %mysql%\lib\libmysql.lib

    Is that for mingw compiler ?

    Anyway, your installation must be working if you can get Qt to connect to local host using the same app.

    So it seems like firewall or something like that if only difference is remote ip versus local ip.



  • thats sort of what im feeling too. ill give it a go and get back with ya



  • @mrjj YAHTZEE!

    it was the MYSQL user permissions. the user i was attempting to connect with was bound to localhost. err on my part. thank you for your guidance through these troubled waters


Log in to reply
 

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