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. QT is not able to connect to MySQL.
Forum Updated to NodeBB v4.3 + New Features

QT is not able to connect to MySQL.

Scheduled Pinned Locked Moved Unsolved General and Desktop
36 Posts 6 Posters 5.4k 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.
  • J Jesus Ocegueda
    30 Mar 2021, 06:45

    @KroMignon said in QT is not able to connect to MySQL.:

    @Jesus-Ocegueda said in QT is not able to connect to MySQL.:

    if(baseDatos.open()){
        qDebug() << "Data base is open";
    }
    else{
        qDebug() << "Data base is NOT open";
    }
    

    I would suggest you to change this to:

    if(baseDatos.open()){
        qDebug() << "Data base is open";
    }
    else{
        qDebug() << "Data base is NOT open:" << baseDatos.lastError().text();
    }
    

    How did you install Qt-Kit on your PC, with MaintenanceTool or with the packet manager of your Linux distribution?
    AFAIK, starting with Qt 5.12.x, the MySQL plugin is only distributed with MaintenanceTool as sources and must be build by yourself, because of Oracle/MySQL licencing changes.

    => https://doc.qt.io/qt-5.12/sql-driver.html#how-to-build-the-qmysql-plugin-on-unix-and-macos

    This is what I got: "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) QMYSQL: Unable to connect"

    K Offline
    K Offline
    KroMignon
    wrote on 30 Mar 2021, 06:57 last edited by KroMignon
    #11

    @Jesus-Ocegueda said in QT is not able to connect to MySQL.:

    This is what I got: "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) QMYSQL: Unable to connect"

    It looks like that the MySQL plugin is there.
    Are you sure that you setup the right connection options?
    You could test it with the console client:

    mysql --host=localhost --port=3306 --user=admin51 --password=hola1234 tarea
    

    cf. https://dev.mysql.com/doc/refman/8.0/en/connecting.html

    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

    J 1 Reply Last reply 30 Mar 2021, 17:50
    1
    • S SGaist
      30 Mar 2021, 06:18

      Since you are using a pretty recent Linux distribution, you might want to consider using the Qt version provided by it rather than building the plugin yourself (not that it is something hard though).

      J Offline
      J Offline
      Jesus Ocegueda
      wrote on 30 Mar 2021, 17:35 last edited by Jesus Ocegueda
      #12

      @SGaist said in QT is not able to connect to MySQL.:

      Since you are using a pretty recent Linux distribution, you might want to consider using the Qt version provided by it rather than building the plugin yourself (not that it is something hard though).

      You recommend uninstall QT and install it from the terminal?
      LIke this: https://www.osradar.com/install-qtcreator-on-ubuntu-20-04-18-04/

      1 Reply Last reply
      0
      • K KroMignon
        30 Mar 2021, 06:57

        @Jesus-Ocegueda said in QT is not able to connect to MySQL.:

        This is what I got: "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) QMYSQL: Unable to connect"

        It looks like that the MySQL plugin is there.
        Are you sure that you setup the right connection options?
        You could test it with the console client:

        mysql --host=localhost --port=3306 --user=admin51 --password=hola1234 tarea
        

        cf. https://dev.mysql.com/doc/refman/8.0/en/connecting.html

        J Offline
        J Offline
        Jesus Ocegueda
        wrote on 30 Mar 2021, 17:50 last edited by
        #13

        @KroMignon said in QT is not able to connect to MySQL.:

        mysql --host=localhost --port=3306 --user=admin51 --password=hola1234 tarea

        This is the output I got after running the command line your gave me:

        jesus@jesus-Inspiron-5559:~$ mysql --host=localhost --port=3306 --user=admin51 --password=hola1234 tarea
        mysql: [Warning] Using a password on the command line interface can be insecure.
        Reading table information for completion of table and column names
        You can turn off this feature to get a quicker startup with -A

        Welcome to the MySQL monitor. Commands end with ; or \g.
        Your MySQL connection id is 8
        Server version: 8.0.23-0ubuntu0.20.04.1 (Ubuntu)

        Copyright (c) 2000, 2021, Oracle and/or its affiliates.

        Oracle is a registered trademark of Oracle Corporation and/or its
        affiliates. Other names may be trademarks of their respective
        owners.

        Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

        mysql>

        1 Reply Last reply
        0
        • J jsulm
          30 Mar 2021, 05:18

          @Jesus-Ocegueda said in QT is not able to connect to MySQL.:

          but it seems I'm unable to do so

          What exactly happens?

          Set QT_DEBUG_PLUGINS environment variable before starting your app and post its output (https://doc.qt.io/qt-5/debug.html).

          J Offline
          J Offline
          Jesus Ocegueda
          wrote on 30 Mar 2021, 18:06 last edited by
          #14

          @jsulm said in QT is not able to connect to MySQL.:

          @Jesus-Ocegueda said in QT is not able to connect to MySQL.:

          but it seems I'm unable to do so

          What exactly happens?

          Set QT_DEBUG_PLUGINS environment variable before starting your app and post its output (https://doc.qt.io/qt-5/debug.html).

          How do I set that? Would you mind give me an example?

          I'm guessing that I only need to place it right after my libraries on my mainwindow.cpp file. Is that correct?
          LIke: QT_DEBUG_PLUGINS;

          I'm not sure because this is my first time with C++

          J 1 Reply Last reply 30 Mar 2021, 18:10
          0
          • J Jesus Ocegueda
            30 Mar 2021, 18:06

            @jsulm said in QT is not able to connect to MySQL.:

            @Jesus-Ocegueda said in QT is not able to connect to MySQL.:

            but it seems I'm unable to do so

            What exactly happens?

            Set QT_DEBUG_PLUGINS environment variable before starting your app and post its output (https://doc.qt.io/qt-5/debug.html).

            How do I set that? Would you mind give me an example?

            I'm guessing that I only need to place it right after my libraries on my mainwindow.cpp file. Is that correct?
            LIke: QT_DEBUG_PLUGINS;

            I'm not sure because this is my first time with C++

            J Offline
            J Offline
            JonB
            wrote on 30 Mar 2021, 18:10 last edited by
            #15

            @Jesus-Ocegueda
            I'm guessing you run your program from within Qt Creator? In which case you need to set it as a runtime environment variable for when your program is executed.

            If you know how to run your executable from a terminal you need to type export QT_DEBUG_PLUGINS=1 there.

            J 1 Reply Last reply 30 Mar 2021, 18:45
            1
            • C Online
              C Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 30 Mar 2021, 18:15 last edited by
              #16

              Since the mysql plugin is properly loaded there is no problem with Qt at all. Please read e.g. here: https://www.dailyrazor.com/blog/cant-connect-to-local-mysql-server-through-socket/ - the first idea would be to use 127.0.0.1 as suggested there so no local socket but tcp/ip is used.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              J 1 Reply Last reply 30 Mar 2021, 18:27
              2
              • C Christian Ehrlicher
                30 Mar 2021, 18:15

                Since the mysql plugin is properly loaded there is no problem with Qt at all. Please read e.g. here: https://www.dailyrazor.com/blog/cant-connect-to-local-mysql-server-through-socket/ - the first idea would be to use 127.0.0.1 as suggested there so no local socket but tcp/ip is used.

                J Offline
                J Offline
                Jesus Ocegueda
                wrote on 30 Mar 2021, 18:27 last edited by Jesus Ocegueda
                #17

                @Christian-Ehrlicher said in QT is not able to connect to MySQL.:

                Since the mysql plugin is properly loaded there is no problem with Qt at all. Please read e.g. here: https://www.dailyrazor.com/blog/cant-connect-to-local-mysql-server-through-socket/ - the first idea would be to use 127.0.0.1 as suggested there so no local socket but tcp/ip is used.

                I follow the article and doing the first instruction I got this:

                jesus@jesus-Inspiron-5559:~$ mysqladmin -u root -p status
                Enter password:
                mysqladmin: connect to server at 'localhost' failed
                error: 'Access denied for user 'root'@'localhost''

                After I try the option u provided I got this in QT:

                Data base is NOT open "SSL connection error: unknown error number QMYSQL: Unable to connect"

                I found intriguing that 'root'@__'localhost''__ it has another ' after host. Should I consider that too?

                I also run sudo mysql and here are the users I have:

                jesus@jesus-Inspiron-5559:~$ sudo mysql
                [sudo] password for jesus:
                Welcome to the MySQL monitor. Commands end with ; or \g.
                Your MySQL connection id is 13
                Server version: 8.0.23-0ubuntu0.20.04.1 (Ubuntu)

                Copyright (c) 2000, 2021, Oracle and/or its affiliates.

                Oracle is a registered trademark of Oracle Corporation and/or its
                affiliates. Other names may be trademarks of their respective
                owners.

                Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

                mysql> SELECT user, authentication_string,plugin,host FROM msql.user;
                ERROR 1049 (42000): Unknown database 'msql'
                mysql> SELECT user, authentication_string,plugin,host FROM mysql.user;
                +------------------+------------------------------------------------------------------------+-----------------------+-----------+
                | user | authentication_string | plugin | host |
                +------------------+------------------------------------------------------------------------+-----------------------+-----------+
                | admin51 | $A$005$9T
                T^&)o@TW^Q-h_&oT.MY9ehrMXFyNzv8k33JesTDZXuHjqUMWeSdvI14f22 | caching_sha2_password | % |
                | debian-sys-maint | $A$005$(t[Bxr/[VJ_%KIDDL2c8KVbWsqR4cm7eSWTfZtbj1Y7HHnMl3IrkUhJr5 | caching_sha2_password | localhost |
                | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | localhost |
                | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | localhost |
                | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | localhost |
                | phpmyadmin | $A$005$:;]J;=H]l9 }E|QYK8HLtTg7fPJ7r3DC.syBTVait3ZiLHSfUaGEKiKkF0 | caching_sha2_password | localhost |
                | root | | auth_socket | localhost |
                +------------------+------------------------------------------------------------------------+-----------------------+-----------+
                7 rows in set (0.01 sec)

                mysql>

                1 Reply Last reply
                0
                • J JonB
                  30 Mar 2021, 18:10

                  @Jesus-Ocegueda
                  I'm guessing you run your program from within Qt Creator? In which case you need to set it as a runtime environment variable for when your program is executed.

                  If you know how to run your executable from a terminal you need to type export QT_DEBUG_PLUGINS=1 there.

                  J Offline
                  J Offline
                  Jesus Ocegueda
                  wrote on 30 Mar 2021, 18:45 last edited by
                  #18

                  @JonB said in QT is not able to connect to MySQL.:

                  @Jesus-Ocegueda
                  I'm guessing you run your program from within Qt Creator? In which case you need to set it as a runtime environment variable for when your program is executed.

                  If you know how to run your executable from a terminal you need to type export QT_DEBUG_PLUGINS=1 there.

                  How do I run it from terminal?
                  Should I just open a terminal on the folder my .pro file is?

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 30 Mar 2021, 18:52 last edited by
                    #19

                    Just do the export, it will be valid for the terminal session until you unset it or close the terminal.

                    Then go to the folder where your application is and execute it.

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

                    J 1 Reply Last reply 30 Mar 2021, 19:08
                    0
                    • S SGaist
                      30 Mar 2021, 18:52

                      Just do the export, it will be valid for the terminal session until you unset it or close the terminal.

                      Then go to the folder where your application is and execute it.

                      J Offline
                      J Offline
                      Jesus Ocegueda
                      wrote on 30 Mar 2021, 19:08 last edited by
                      #20

                      @SGaist said in QT is not able to connect to MySQL.:

                      Just do the export, it will be valid for the terminal session until you unset it or close the terminal.

                      Then go to the folder where your application is and execute it.

                      I bet this is easy but I don't get how to proceed when you say export, will you mind explain that or how to look it up that on google to search how to do that

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 30 Mar 2021, 19:20 last edited by
                        #21

                        @JonB already wrote what to do:
                        @JonB said in QT is not able to connect to MySQL.:

                        type export QT_DEBUG_PLUGINS=1

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

                        J 1 Reply Last reply 31 Mar 2021, 06:36
                        0
                        • S SGaist
                          30 Mar 2021, 19:20

                          @JonB already wrote what to do:
                          @JonB said in QT is not able to connect to MySQL.:

                          type export QT_DEBUG_PLUGINS=1

                          J Offline
                          J Offline
                          Jesus Ocegueda
                          wrote on 31 Mar 2021, 06:36 last edited by
                          #22

                          @SGaist said in QT is not able to connect to MySQL.:

                          @JonB already wrote what to do:
                          @JonB said in QT is not able to connect to MySQL.:

                          type export QT_DEBUG_PLUGINS=1

                          The thing is that I don't know how to run it from the terminal, I do not understand the process, and I know this forum is not for C++, my bad :(

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 31 Mar 2021, 06:51 last edited by
                            #23

                            This has nothing to do with C++ in this case, it's the Linux export command.

                            The instruction is literally: Type export QT_DEBUG_PLUGINS=1 into your terminal. There's nothing more to it.

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

                            J 1 Reply Last reply 31 Mar 2021, 07:14
                            0
                            • S SGaist
                              31 Mar 2021, 06:51

                              This has nothing to do with C++ in this case, it's the Linux export command.

                              The instruction is literally: Type export QT_DEBUG_PLUGINS=1 into your terminal. There's nothing more to it.

                              J Offline
                              J Offline
                              Jesus Ocegueda
                              wrote on 31 Mar 2021, 07:14 last edited by
                              #24

                              @SGaist said in QT is not able to connect to MySQL.:

                              This has nothing to do with C++ in this case, it's the Linux export command.

                              The instruction is literally: Type export QT_DEBUG_PLUGINS=1 into your terminal. There's nothing more to it.

                              Alrighty!
                              As soon as I open the terminal I type that’s but it shows no output. Should I open the terminal on the folder where my project is?

                              J 1 Reply Last reply 31 Mar 2021, 07:17
                              0
                              • J Jesus Ocegueda
                                31 Mar 2021, 07:14

                                @SGaist said in QT is not able to connect to MySQL.:

                                This has nothing to do with C++ in this case, it's the Linux export command.

                                The instruction is literally: Type export QT_DEBUG_PLUGINS=1 into your terminal. There's nothing more to it.

                                Alrighty!
                                As soon as I open the terminal I type that’s but it shows no output. Should I open the terminal on the folder where my project is?

                                J Offline
                                J Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on 31 Mar 2021, 07:17 last edited by
                                #25

                                @Jesus-Ocegueda said in QT is not able to connect to MySQL.:

                                As soon as I open the terminal I type that’s but it shows no output

                                After typing this command you need to start the app (in same terminal):

                                export QT_DEBUG_PLUGINS=1
                                ./my_app_exe
                                

                                If you want to start from QtCreator then set QT_DEBUG_PLUGINS in Projects/Build & Run/Run/Run Environment".

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                J 1 Reply Last reply 31 Mar 2021, 07:27
                                0
                                • J jsulm
                                  31 Mar 2021, 07:17

                                  @Jesus-Ocegueda said in QT is not able to connect to MySQL.:

                                  As soon as I open the terminal I type that’s but it shows no output

                                  After typing this command you need to start the app (in same terminal):

                                  export QT_DEBUG_PLUGINS=1
                                  ./my_app_exe
                                  

                                  If you want to start from QtCreator then set QT_DEBUG_PLUGINS in Projects/Build & Run/Run/Run Environment".

                                  J Offline
                                  J Offline
                                  Jesus Ocegueda
                                  wrote on 31 Mar 2021, 07:27 last edited by
                                  #26

                                  @jsulm said in QT is not able to connect to MySQL.:

                                  @Jesus-Ocegueda said in QT is not able to connect to MySQL.:

                                  As soon as I open the terminal I type that’s but it shows no output

                                  After typing this command you need to start the app (in same terminal):

                                  export QT_DEBUG_PLUGINS=1
                                  ./my_app_exe
                                  

                                  If you want to start from QtCreator then set QT_DEBUG_PLUGINS in Projects/Build & Run/Run/Run Environment".

                                  So instead of ./my_app_exe it will be ./qt?

                                  J 1 Reply Last reply 31 Mar 2021, 07:38
                                  0
                                  • J Jesus Ocegueda
                                    31 Mar 2021, 07:27

                                    @jsulm said in QT is not able to connect to MySQL.:

                                    @Jesus-Ocegueda said in QT is not able to connect to MySQL.:

                                    As soon as I open the terminal I type that’s but it shows no output

                                    After typing this command you need to start the app (in same terminal):

                                    export QT_DEBUG_PLUGINS=1
                                    ./my_app_exe
                                    

                                    If you want to start from QtCreator then set QT_DEBUG_PLUGINS in Projects/Build & Run/Run/Run Environment".

                                    So instead of ./my_app_exe it will be ./qt?

                                    J Offline
                                    J Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on 31 Mar 2021, 07:38 last edited by
                                    #27

                                    @Jesus-Ocegueda said in QT is not able to connect to MySQL.:

                                    So instead of ./my_app_exe it will be ./qt?

                                    Instead of my_app_exe you use the name of your executable

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    J 1 Reply Last reply 31 Mar 2021, 15:10
                                    0
                                    • J jsulm
                                      31 Mar 2021, 07:38

                                      @Jesus-Ocegueda said in QT is not able to connect to MySQL.:

                                      So instead of ./my_app_exe it will be ./qt?

                                      Instead of my_app_exe you use the name of your executable

                                      J Offline
                                      J Offline
                                      Jesus Ocegueda
                                      wrote on 31 Mar 2021, 15:10 last edited by
                                      #28

                                      @jsulm said in QT is not able to connect to MySQL.:

                                      @Jesus-Ocegueda said in QT is not able to connect to MySQL.:

                                      So instead of ./my_app_exe it will be ./qt?

                                      Instead of my_app_exe you use the name of your executable

                                      You mean my .pro file?

                                      J 1 Reply Last reply 31 Mar 2021, 15:14
                                      0
                                      • J Jesus Ocegueda
                                        31 Mar 2021, 15:10

                                        @jsulm said in QT is not able to connect to MySQL.:

                                        @Jesus-Ocegueda said in QT is not able to connect to MySQL.:

                                        So instead of ./my_app_exe it will be ./qt?

                                        Instead of my_app_exe you use the name of your executable

                                        You mean my .pro file?

                                        J Offline
                                        J Offline
                                        JonB
                                        wrote on 31 Mar 2021, 15:14 last edited by
                                        #29

                                        @Jesus-Ocegueda

                                        You mean my .pro file?

                                        No, the executable program which you build and run all the time.

                                        J 1 Reply Last reply 31 Mar 2021, 15:37
                                        0
                                        • J JonB
                                          31 Mar 2021, 15:14

                                          @Jesus-Ocegueda

                                          You mean my .pro file?

                                          No, the executable program which you build and run all the time.

                                          J Offline
                                          J Offline
                                          Jesus Ocegueda
                                          wrote on 31 Mar 2021, 15:37 last edited by
                                          #30

                                          @JonB said in QT is not able to connect to MySQL.:

                                          @Jesus-Ocegueda

                                          You mean my .pro file?

                                          No, the executable program which you build and run all the time.
                                          Alrighty, that will be the mainwindow.cpp

                                          J 2 Replies Last reply 31 Mar 2021, 16:24
                                          0

                                          20/36

                                          30 Mar 2021, 19:08

                                          • Login

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