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 7.1k 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.
  • SGaistS SGaist

    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 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
    • KroMignonK KroMignon

      @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 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
      • jsulmJ jsulm

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

        JonBJ 1 Reply Last reply
        0
        • J Jesus Ocegueda

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

          JonBJ Online
          JonBJ Online
          JonB
          wrote on 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
          1
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 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
            2
            • Christian EhrlicherC Christian Ehrlicher

              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 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
              • JonBJ JonB

                @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 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
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 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
                  0
                  • SGaistS SGaist

                    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 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
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 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
                      0
                      • SGaistS SGaist

                        @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 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
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 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
                          0
                          • SGaistS SGaist

                            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 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?

                            jsulmJ 1 Reply Last reply
                            0
                            • J Jesus Ocegueda

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

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on 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
                              0
                              • jsulmJ jsulm

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

                                jsulmJ 1 Reply Last reply
                                0
                                • J Jesus Ocegueda

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

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on 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
                                  0
                                  • jsulmJ jsulm

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

                                    JonBJ 1 Reply Last reply
                                    0
                                    • J Jesus Ocegueda

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

                                      JonBJ Online
                                      JonBJ Online
                                      JonB
                                      wrote on 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
                                      0
                                      • JonBJ JonB

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

                                        JonBJ 2 Replies Last reply
                                        0
                                        • J Jesus Ocegueda

                                          @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

                                          JonBJ Online
                                          JonBJ Online
                                          JonB
                                          wrote on last edited by
                                          #31

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

                                          Alrighty, that will be the mainwindow.cpp

                                          I'm afraid not, that is a source code file! No use at all here....

                                          Have you ever written source code for a compiled language like C++ before? To be fair, since you reference phpmyadmin, you may not have done. But then there is a big comprehension leap.

                                          Do you understand what is going on when you type some code into a C++ file in Qt Creator and press one the Build (or Run or Debug) buttons? You don't need to know all the details, but I do think you should read up on what "compilation" is all about, because it will help with other things.

                                          J 1 Reply Last reply
                                          1

                                          • Login

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