Sharing Database between Apps
-
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?
-
@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.
-
@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!
-
@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?
-
@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.
-
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;
-
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.
-
-