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


  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
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

Cloudron Forum

Apps | Demo | Docs | Install

Sharing Database between Apps

Scheduled Pinned Locked Moved Solved Support
database
8 Posts 2 Posters 251 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.
  • brianbB Offline
    brianbB Offline
    brianb
    wrote on last edited by girish
    #1

    Is it possible to share a database between apps?

    Specifically for me to access the database for Ghost (mysql) with Discourse? Each installed via Cloudron so they are isolated within the same server. Is it possible to share a port between apps without opening it to to public?

    girishG 1 Reply Last reply
    1
  • girishG Offline
    girishG Offline
    girish Staff
    replied to brianb on last edited by
    #0

    @briankb-0 apps can't share the same database in Cloudron. But they can access each other's database.

    For example, if you want to access Ghost's database from another app, you can go to Ghost's Web Terminal and type env | grep MYSQL . That gives the credentials Ghost is using to connect to the database. Those credentials work from any app.

    Important notes: Do not change Discourse's own database to the values above! As mentioned, apps cannot have a single database on Cloudron, each app gets it's own database.

    The database credentials of an app can potentially change when you restore an app but they are retained across updates.

    Other use cases: we use this to access the database of other apps via metabase. Metabase also has a way to use a "readonly" connection. Definitely use this, if it's possible.

    brianbB 1 Reply Last reply
    1
  • girishG Offline
    girishG Offline
    girish Staff
    replied to brianb on last edited by
    #2

    @briankb-0 apps can't share the same database in Cloudron. But they can access each other's database.

    For example, if you want to access Ghost's database from another app, you can go to Ghost's Web Terminal and type env | grep MYSQL . That gives the credentials Ghost is using to connect to the database. Those credentials work from any app.

    Important notes: Do not change Discourse's own database to the values above! As mentioned, apps cannot have a single database on Cloudron, each app gets it's own database.

    The database credentials of an app can potentially change when you restore an app but they are retained across updates.

    Other use cases: we use this to access the database of other apps via metabase. Metabase also has a way to use a "readonly" connection. Definitely use this, if it's possible.

    brianbB 1 Reply Last reply
    1
  • brianbB Offline
    brianbB Offline
    brianb
    replied to girish on last edited by girish
    #3

    @girish Thank you!

    The more I learn how to use Cloudron the more impressive it is!

    Great job!

    I've used many similar apps/code over the years to manage a VPS or Server and Cloundron continues to have an answer. Your support via email AND forum is equally impressive and much appreciated!

    brianbB 1 Reply Last reply
    1
  • brianbB Offline
    brianbB Offline
    brianb
    replied to brianb on last edited by brianb
    #4

    @briankb-0 What is the correct host address to use to connect to another apps mysql db?

    I tried what was shown in the output from grep mysql which is "HOST=mysql" as well as what was shown for "URL" but neither worked.

    Also is this working because cloundron allows by default remote connections to mysql database or is it all internal to server with nothing exposed beyond firewall?

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

    @briankb-0 said in Sharing Database between Apps:

    I tried what was shown in the output from grep mysql which is "HOST=mysql" as well as what was shown for "URL" but neither worked.

    The internal hostname is indeed mysql. Can you tell me what you tried and where?

    Also is this working because cloudron allows by default remote connections to mysql database or is it all internal to server with nothing exposed beyond firewall?

    Remote connections are entirely disabled, you cannot connect from inside. There is an internal server private network. MySql and the app containers reside there in the 172.18.x.x network.

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

    So, like this. I can do this in a LAMP app's Web Terminal:

    root@6bd858ec-a89f-435a-a5dd-efd175ea3e87:/app/code# env | grep MYSQL
    CLOUDRON_MYSQL_HOST=mysql
    CLOUDRON_MYSQL_USERNAME=59119e3970882eaa
    CLOUDRON_MYSQL_PORT=3306
    CLOUDRON_MYSQL_DATABASE=59119e3970882eaa
    CLOUDRON_MYSQL_URL=mysql://59119e3970882eaa:3fe0c668e8ecea945585498b264d1438e82cc0a348625741@mysql/59119e3970882eaa
    CLOUDRON_MYSQL_PASSWORD=3fe0c668e8ecea945585498b264d1438e82cc0a348625741
    

    Then, to test the connection, I can use the credentials above to connect from another app's Web Terminal:

    root@ae0f8318-37f1-4ffe-9e7b-28d3398a4bc3:/app/code# mysql --user=59119e3970882eaa --password=3fe0c668e8ecea945585498b264d1438e82cc0a348625741 --host=mysql 59119e3970882eaa
    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 3734
    Server version: 8.0.28-0ubuntu0.20.04.3 (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> show tables;
    
    1 Reply Last reply
    2
  • girishG Offline
    girishG Offline
    girish Staff
    wrote on last edited by
    #7

    BTW, one "trick" to know is that in the Web Terminal, there are buttons on the top called MySQL. If you click on them, it will paste the CLI command to connect to the database. Just press enter and it will connect.

    brianbB 1 Reply Last reply
    3
  • brianbB Offline
    brianbB Offline
    brianb
    replied to girish on last edited by
    #8

    @girish the example command did the trick! I was not using the correct syntax but also I didn't specify the database name. Once I did that I was able to reach the Ghost mysql database from the Discourse app 🙂

    1 Reply Last reply
    0
  • girishG girish marked this topic as a question on
  • girishG girish has marked this topic as solved on

  • Login

  • Don't have an account? Register

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

  • Don't have an account? Register

  • Login or register to search.