Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps | Demo | Docs | Install
  1. Cloudron Forum
  2. Minecraft
  3. Connect minecraft server to LAMP Stack's MySQL

Connect minecraft server to LAMP Stack's MySQL

Scheduled Pinned Locked Moved Solved Minecraft
mysqllampfeature-requestminecraft
10 Posts 2 Posters 2.1k 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.
  • T Offline
    T Offline
    Trankery
    wrote on last edited by girish
    #1

    Title explains it already.

    I'm looking to connect my minecraft server to the lamp stack's database, but this isn't possible.

    Neither is it possible to connect to the MC Server's Database, as the hostname gets rewritten by cloudron automatically to localhost.

    Please fix this or let me know how I can make either database accessible.

    1 Reply Last reply
    0
    • girishG Offline
      girishG Offline
      girish
      Staff
      wrote on last edited by
      #2

      If minecraft is on Cloudron as well, then you can just use the MySQL credentials of the LAMP app directly. You can get the credentials by opening a web terminal for the LAMP app and then running this:

         env | grep CLOUDRON_MYSQL
      

      If minecraft is one a different server, it's more complicated because the MySQL addon is completely sandboxed in the sever. But it's possible (can explain more, if this is the case).

      T 1 Reply Last reply
      0
      • girishG Offline
        girishG Offline
        girish
        Staff
        wrote on last edited by girish
        #3

        Here's a more complete tutorial.

        • First open the web terminal for the lamp app. Get the MySQL access credentials. Note that the credentials only work inside Cloudron server.
        root@f6af0aef-2e29-4b53-a674-c2eed67eea36:/app/data# env | grep MYSQL
        MYSQL_PASSWORD=9458c46184b6337677f058fbd53c089a317e6b2f5e321b1d
        MYSQL_DATABASE=0133aefa8ed2d231
        MYSQL_PORT=3306
        MYSQL_HOST=mysql
        MYSQL_USERNAME=0133aefa8ed2d231
        MYSQL_URL=mysql://0133aefa8ed2d231:9458c46184b6337677f058fbd53c089a317e6b2f5e321b1d@mysql/0133aefa8ed2d231
        
        • SSH into the Cloudron server and get the IP address of the mysql container.
        root@localhost:~# docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql
        172.18.0.5
        
        • SSH into the Cloudron server to verify that we can connect to the app's database. Carefully plug the values from the env vars into the command line below.
        root@localhost:~# mysql --user=0133aefa8ed2d231 --password=9458c46184b6337677f058fbd53c089a317e6b2f5e321b1d --host=172.18.0.5 --port=3306 0133aefa8ed2d231
        mysql: [Warning] Using a password on the command line interface can be insecure.
        Welcome to the MySQL monitor.  Commands end with ; or \g.
        Your MySQL connection id is 8037
        Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)
        
        Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
        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>  show tables;
        
        • Now to connect to this mysql server from another server or your laptop, you have to create a SSH tunnel. Run this command on the other server or your laptop:
        $ ssh -N -L 127.0.0.1:3306:172.18.0.5:3306 root@my.cloudron.domain
        

        What this command is doing is connecting to your Cloudron via SSH. The -L sets up port forwarding. It forward port 3306 of 127.0.0.1 (localhost) to port 3306 of 172.18.0.5 (mysql).

        • We can now connect to port 3306 of 127.0.0.1 to access mysql:
        $ mysql --user=0133aefa8ed2d231 --password=9458c46184b6337677f058fbd53c089a317e6b2f5e321b1d --host=127.0.0.1 --port=3306 0133aefa8ed2d231
        mysql: [Warning] Using a password on the command line interface can be insecure.
        Welcome to the MySQL monitor.  Commands end with ; or \g.
        Your MySQL connection id is 8038
        Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)
        
        Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
        
        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> show tables;
        Empty set (0.01 sec)
        
        • Some additional thoughts. If you want the ssh proxying to persist in your laptop/other server, use autossh. https://pronto185.com/blog/2014/01/30/how-i-use-autossh/ has a simple tutorial. For windows, there is https://persistentssh.com/ (I have never used it).
        1 Reply Last reply
        0
        • girishG girish

          If minecraft is on Cloudron as well, then you can just use the MySQL credentials of the LAMP app directly. You can get the credentials by opening a web terminal for the LAMP app and then running this:

             env | grep CLOUDRON_MYSQL
          

          If minecraft is one a different server, it's more complicated because the MySQL addon is completely sandboxed in the sever. But it's possible (can explain more, if this is the case).

          T Offline
          T Offline
          Trankery
          wrote on last edited by
          #4

          @girish the server is on a completely different host, and I do not have system access.

          1 Reply Last reply
          0
          • girishG Offline
            girishG Offline
            girish
            Staff
            wrote on last edited by
            #5

            Does minecraft support connecting to mysql via ssh+tcp connection? Like how mysql workbench does it - MySQL Server using TCP/IP over an SSH connection. See https://dev.mysql.com/doc/workbench/en/wb-mysql-connections-methods-ssh.html

            T 1 Reply Last reply
            0
            • girishG girish

              Does minecraft support connecting to mysql via ssh+tcp connection? Like how mysql workbench does it - MySQL Server using TCP/IP over an SSH connection. See https://dev.mysql.com/doc/workbench/en/wb-mysql-connections-methods-ssh.html

              T Offline
              T Offline
              Trankery
              wrote on last edited by
              #6

              @girish No, I simply have the option to enter IP/Hostname, port, username, db name and password.

              1 Reply Last reply
              0
              • girishG Offline
                girishG Offline
                girish
                Staff
                wrote on last edited by
                #7

                I see, I think this can be done with some socat forwarding. I will try tomorrow.

                1 Reply Last reply
                0
                • girishG Offline
                  girishG Offline
                  girish
                  Staff
                  wrote on last edited by girish
                  #8

                  How about this then. On Cloudron, install socat and also open up port 5555 in iptables. Then just forward port 5555 to the internal mysql.

                  root@localhost:~# apt install socat
                  root@localhost:~# iptables -I INPUT -p tcp --dport 5555 -j ACCEPT
                  root@localhost:~# mkdir /etc/iptables
                  root@localhost:~# iptables-save > /etc/iptables/rules.v4
                  root@localhost:~# docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql
                  172.18.0.4
                  root@localhost:~# socat TCP-LISTEN:5555,fork TCP:172.18.0.4:3306
                  
                  • Then you can connect from your PC or minecraft server to the sql server using port 5555 as:
                  $ mysql --user=e89d41145799e97 --password=e97e3fb41f3e52dd2462997d6008ccc0e0b0cffb9443b4ff --host=my.cloudron.domain --port=5555 e89d41668599e97
                  mysql> show tables;
                  Empty set (0.01 sec)
                  

                  You have to install the socat as a systemd service or such to make it persist reboots. Otherwise, just use nohup socat TCP-LISTEN:5555,fork TCP:172.18.0.4:3306 &

                  1 Reply Last reply
                  1
                  • T Offline
                    T Offline
                    Trankery
                    wrote on last edited by
                    #9

                    Thank you so much!

                    Maybe make it an option to disable/enable the public access to the mysql server. Would be really great. Thanks!

                    1 Reply Last reply
                    0
                    • girishG Offline
                      girishG Offline
                      girish
                      Staff
                      wrote on last edited by
                      #10

                      @Trankery Yup, I will mark this as a feature request for a future release.

                      1 Reply Last reply
                      2
                      • C cdrm referenced this topic on
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Bookmarks
                      • Search