Docs

Databases

Connecting your app to its MySQL database.

Each site can have its own MariaDB 11.4 database, compatible with MySQL. It is private to the site, reachable only by its app, and backed up every night. WordPress sites always have one, already connected.

Connection settings

Your container gets these environment variables. Read them in your app rather than typing the values in:

VariableValue
DB_HOST<site name>-db
DB_PORT3306
DB_NAMEsite
DB_USERsite
DB_PASSWORDgenerated for your site and kept secret
DATABASE_URLmysql://site:<password>@<site name>-db:3306/site

Examples

// Node.js (mysql2)
const pool = mysql.createPool(process.env.DATABASE_URL);

// PHP (PDO)
$db = new PDO('mysql:host=' . getenv('DB_HOST') . ';port=' . getenv('DB_PORT') . ';dbname=' . getenv('DB_NAME'),
              getenv('DB_USER'), getenv('DB_PASSWORD'));

# Python (PyMySQL)
db = pymysql.connect(host=os.environ['DB_HOST'], port=int(os.environ['DB_PORT']),
                     user=os.environ['DB_USER'], password=os.environ['DB_PASSWORD'],
                     database=os.environ['DB_NAME'])

// Prisma: datasource db { provider = "mysql"  url = env("DATABASE_URL") }

Laravel reads DB_HOST, DB_PORT and DB_PASSWORD as they are. Add DB_CONNECTION=mysql, DB_DATABASE=site and DB_USERNAME=site to the site’s environment variables.

Tables and migrations

The database starts empty. Create your tables when your app starts, or run migrations from it (for example as its start command before the server). The database may still be starting for the first few seconds, so retry the connection rather than giving up.

Size

Starter: 2 GB; Business: 5 GB.

Importing data, or connecting a tool

The database is not open to the internet. To import an existing database or get a copy, ask us.

Adding a database later

Choose the database when you create the site. To add one to an existing site, ask us.

NextPrivate image registry →