Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. remote mysql database connection
Forum Updated to NodeBB v4.3 + New Features

remote mysql database connection

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mahbad
    wrote on 26 Jun 2017, 18:04 last edited by
    #1

    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

    M 1 Reply Last reply 26 Jun 2017, 18:15
    0
    • M mahbad
      26 Jun 2017, 18:04

      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

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 26 Jun 2017, 18:15 last edited by
      #2

      @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

      1 Reply Last reply
      1
      • M Offline
        M Offline
        mahbad
        wrote on 26 Jun 2017, 19:12 last edited by
        #3

        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

        M 1 Reply Last reply 26 Jun 2017, 19:43
        0
        • M mahbad
          26 Jun 2017, 19:12

          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

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 26 Jun 2017, 19:43 last edited by
          #4

          @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.

          M 1 Reply Last reply 26 Jun 2017, 20:30
          1
          • M Offline
            M Offline
            mahbad
            wrote on 26 Jun 2017, 19:53 last edited by
            #5

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

            1 Reply Last reply
            0
            • M mrjj
              26 Jun 2017, 19:43

              @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.

              M Offline
              M Offline
              mahbad
              wrote on 26 Jun 2017, 20:30 last edited by
              #6

              @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

              1 Reply Last reply
              1

              2/6

              26 Jun 2017, 18:15

              topic:navigator.unread, 4
              • Login

              • Login or register to search.
              2 out of 6
              • First post
                2/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved