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. Connect to remote access raspberry pi with mariadb

Connect to remote access raspberry pi with mariadb

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 6 Posters 2.2k Views
  • 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.
  • H Offline
    H Offline
    hobbyProgrammer
    wrote on last edited by
    #1

    Hi,

    I have a raspberry pi that contains a MySQL database using mariadb.
    I would like to get access to the raspberry pi from my database. My raspberry pi uses remote access.

    I already had it linked to MySQL workbench and it asks me to login twice. One for getting remote access (or access in general) to the raspberry pi, the second one is the login for the database.

    How do I configure this database connection in Qt?

    Pablo J. RoginaP 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      For the database login

          QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
          db.setHostName("REMOTEIP");
          db.setDatabaseName("test");
          db.setUserName("user");
          db.setPassword("pwd");
      

      For the remote access thing. Im not sure what MySQL workbench allows with the remote access stuff so
      i cant comment on that.

      H 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        For the database login

            QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
            db.setHostName("REMOTEIP");
            db.setDatabaseName("test");
            db.setUserName("user");
            db.setPassword("pwd");
        

        For the remote access thing. Im not sure what MySQL workbench allows with the remote access stuff so
        i cant comment on that.

        H Offline
        H Offline
        hobbyProgrammer
        wrote on last edited by
        #3

        @mrjj Hi,yes I know how you would normally log into a database, but I was only wondering how the remote access works and where to implement that in the code.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Gulivert
          wrote on last edited by
          #4

          You get access to your database exactly like @mrjj explain to connect.

          I suppose that you get access to your database from Workbench by using a ssh connection, you have to fill first the SSH connection credential, which is the login and password of your raspberry and then, the login and password of MYSQL, is it correct ?
          If you want an access from your QT app you have to open the MYSQL port in the firewall of your Raspberry, if there is firewall running. Which should be the case in my memory by default in a Raspbian disto for instance.

          Maybe we did not understand what you are talking about a remote access ? Could you explain a bit more.

          H 1 Reply Last reply
          1
          • G Gulivert

            You get access to your database exactly like @mrjj explain to connect.

            I suppose that you get access to your database from Workbench by using a ssh connection, you have to fill first the SSH connection credential, which is the login and password of your raspberry and then, the login and password of MYSQL, is it correct ?
            If you want an access from your QT app you have to open the MYSQL port in the firewall of your Raspberry, if there is firewall running. Which should be the case in my memory by default in a Raspbian disto for instance.

            Maybe we did not understand what you are talking about a remote access ? Could you explain a bit more.

            H Offline
            H Offline
            hobbyProgrammer
            wrote on last edited by
            #5

            @Gulivert Hi, yes the workbench asks for the SSH connection. Is there anyway to fill the SSH connection credentials in Qt?

            jsulmJ 1 Reply Last reply
            0
            • H hobbyProgrammer

              @Gulivert Hi, yes the workbench asks for the SSH connection. Is there anyway to fill the SSH connection credentials in Qt?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @hobbyProgrammer You could use public key authentication: https://serverpilot.io/docs/how-to-use-ssh-public-key-authentication

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

              H 1 Reply Last reply
              1
              • jsulmJ jsulm

                @hobbyProgrammer You could use public key authentication: https://serverpilot.io/docs/how-to-use-ssh-public-key-authentication

                H Offline
                H Offline
                hobbyProgrammer
                wrote on last edited by
                #7

                @jsulm I believe it's already public as I haven't changed it yet and it's still
                username: pi
                password: raspberry

                jsulmJ 1 Reply Last reply
                0
                • H hobbyProgrammer

                  @jsulm I believe it's already public as I haven't changed it yet and it's still
                  username: pi
                  password: raspberry

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by jsulm
                  #8

                  @hobbyProgrammer I think you misunderstand what public key authentication means: if it is set up you don't have to enter your password when logging in via SSH.
                  If you did set up public key authentication properly then you should be able to log in via SSH without password. If it still asks you for password then public key authentication is not set up properly.
                  You have to set it up as you need to upload your public key to your RPi.

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

                  1 Reply Last reply
                  1
                  • H hobbyProgrammer

                    Hi,

                    I have a raspberry pi that contains a MySQL database using mariadb.
                    I would like to get access to the raspberry pi from my database. My raspberry pi uses remote access.

                    I already had it linked to MySQL workbench and it asks me to login twice. One for getting remote access (or access in general) to the raspberry pi, the second one is the login for the database.

                    How do I configure this database connection in Qt?

                    Pablo J. RoginaP Offline
                    Pablo J. RoginaP Offline
                    Pablo J. Rogina
                    wrote on last edited by
                    #9

                    @hobbyProgrammer said in Connect to remote access raspberry pi with mariadb:

                    I already had it linked to MySQL workbench

                    could you please confirm where you're running that application?

                    Upvote the answer(s) that helped you solve the issue
                    Use "Topic Tools" button to mark your post as Solved
                    Add screenshots via postimage.org
                    Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                    H 1 Reply Last reply
                    1
                    • Pablo J. RoginaP Pablo J. Rogina

                      @hobbyProgrammer said in Connect to remote access raspberry pi with mariadb:

                      I already had it linked to MySQL workbench

                      could you please confirm where you're running that application?

                      H Offline
                      H Offline
                      hobbyProgrammer
                      wrote on last edited by
                      #10

                      @Pablo-J-Rogina I have a raspberry pi that contains a mysql mariadb.

                      I also have a PC with MySQL workbench and Qt where I'd like to create and run the application from.

                      Pablo J. RoginaP 1 Reply Last reply
                      0
                      • H hobbyProgrammer

                        @Pablo-J-Rogina I have a raspberry pi that contains a mysql mariadb.

                        I also have a PC with MySQL workbench and Qt where I'd like to create and run the application from.

                        Pablo J. RoginaP Offline
                        Pablo J. RoginaP Offline
                        Pablo J. Rogina
                        wrote on last edited by
                        #11

                        @hobbyProgrammer said in Connect to remote access raspberry pi with mariadb:

                        I also have a PC with MySQL workbench and Qt where I'd like to create and run the application from.

                        Ok, so have you already tried @mrjj suggestion for Qt code to database login?

                        Upvote the answer(s) that helped you solve the issue
                        Use "Topic Tools" button to mark your post as Solved
                        Add screenshots via postimage.org
                        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                        1 Reply Last reply
                        2
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Hi,

                          One important point: if you want to access your database directly from outside of your RPi, you must also configure it to allow that. Having a remote service that access the database locally is not the same as accessing it directly remotely.

                          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
                          1
                          • G Offline
                            G Offline
                            Gulivert
                            wrote on last edited by Gulivert
                            #13

                            From my point of view, if you want to connect your raspberry mariadb from your QT client over a local network you should not use SSH, it will be more pain to do it mainly if it is not needed and doing it like @mrjj explanation.
                            If it's for a local connection inside a company where there is policies which not allow direct connection or over Internet you could use SSH but you need to implement it. I'm not a king in QT but I think there is not "out of the box" class to connect on a SSH server.
                            It is possible to implement SSH connection by using for instance libssh or libssh2 with which you will handle only the connection to the raspberry over this protocol, then when the SSH connection is initialized and OK you have to connect with the regular connection from QsqlDatabase still the same as explain by @mrjj .

                            One more think, for an Internet connection you also can expose your Raspberry MariaDB to internet and have a direct access to it (this is not complicated), but this is not a solution for security reasons.

                            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