Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) QMYSQL: Unable to connect
Forum Updated to NodeBB v4.3 + New Features

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) QMYSQL: Unable to connect

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
6 Posts 2 Posters 1.8k Views 2 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.
  • J Offline
    J Offline
    JarekT
    wrote on 22 Apr 2020, 13:47 last edited by
    #1

    Hi, I'm trying to connect Qt with MySql and when I run my program I get this error:

    Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) QMYSQL: Unable to connect

    I use:
    macOS High Sierra
    XAMPP 7.4.4,
    Qt Creator 5.14.2

    Here is my code:

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost"); //127.0.0.1
    db.setUserName("root");
    db.setPassword("");
    db.setDatabaseName("monitoringDB");
    
    if (!db.open()) {
       qDebug() << "Couldn't open db";
       qDebug() << "Error: " << db.lastError().text();
    } else {
       qDebug() << "DB opened!";
    }
    

    I have XAMPP started up and running, including MySql database. I also checked that my databaseName, userName and password are correct.

    I tried to google the problem but people usually refer to MySql installed separatelly, not within Xampp and their solutions doesn't apply to my case (at least I couldn't sort it out).

    Regarding the error itself in my case '/tmp/mysql.sock' doesn't exist in the filesystem. I cannot see even '/tmp/'

    Can anybody help me please with this because I'm out of ideas at this point..
    Additionally can you say from your experience if using Xampp with Qt is a good idea? or maybe I should install all components (Apache, MySql, PHP) individually?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 22 Apr 2020, 18:08 last edited by
      #2

      Hi and welcome to devnet,

      How exactly did you configure MySQL ?
      Can you connect to it from the command line ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JarekT
        wrote on 23 Apr 2020, 06:39 last edited by
        #3

        Installing Xampp doesn't require any additional configuration of MySql. However I did use brew install mysql-client and it was successful. After that I compiled qt sources: sqldrivers.pro and mysql.pro (I added two lines to mysql.pro file: INCLUDEPATH and QMAKE_LIBDIR). Afterwards I did "make" to all. As a result I had libqsqlmysql.dylib and I copied it into .../clang_64/plugins/sqldrivers. I've checked and libqsqlmysql.dylib refers to libmysqlclient.21.dylib which is correct (this is the one I have).

        When I type mysql -u root -p in the terminal I get:
        ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

        Now I also try to do the same project on Ubuntu to see how it goes, but this time I do not use Xampp but I am installing and configuring everything separately. Do you think it is a better approach? Is it Xampp which is making things complicated?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 23 Apr 2020, 19:01 last edited by
          #4

          @JarekT said in Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) QMYSQL: Unable to connect:

          Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

          Check your MySQL configuration to see where that socket is configured to be.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JarekT
            wrote on 24 Apr 2020, 12:49 last edited by
            #5

            How can I check it??
            What I was able to find where mysql.sock is. I have it at:
            /Users/jarek/.bitnami/stackman/machines/xampp/volumes/root/var/mysql/mysql.sock

            I tried to do a symbolic link of this file to /tmp/mysql.sock but it didn't work..

            1 Reply Last reply
            0
            • J Offline
              J Offline
              JarekT
              wrote on 24 Apr 2020, 14:01 last edited by
              #6

              I found that I can do some configuration in my.cnf file (location: /Users/jarek/.bitnami/stackman/machines/xampp/volumes/root/etc/my.cnf). I have read somewhere that I need to copy it to /etc/my.cnf to have a possibility to change it. So I copied it there. Afterwards I changed the following:
              socket =/opt/lampp/var/mysql/mysql.sock -->> changed to -->> socket =/Users/jarek/.bitnami/stackman/machines/xampp/volumes/root/var/mysql/mysql.sock
              and
              plugin_dir=/opt/lampp/lib/mysql/plugin/ -->> changed to -->> plugin_dir=/Users/jarek/.bitnami/stackman/machines/xampp/volumes/root/lib/mysql/plugin/

              Now when I do sudo mysql I have:
              ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Users/jarek/.bitnami/stackman/machines/xampp/volumes/root/var/mysql/mysql.sock' (61) so it didn't help...

              1 Reply Last reply
              0

              1/6

              22 Apr 2020, 13:47

              • Login

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