MySQL exists in two forms on Webgune: a managed database, on the shared database servers, and a project database, in MySQL 8.4. It is the engine WordPress, Laravel and most PHP applications expect. The full comparison is on Databases.
| Managed database | Project database | |
|---|---|---|
| Port | 3306 | 3306 |
| TLS | required | not required |
| User | same name as the database (wg_<prefix>_<name>) | kxuser, unless you chose otherwise at creation |
| Character set | utf8mb4 | MySQL 8.4's default setting (utf8mb4) |
| Size | 500 MB without a subscription, 10 GB with one | 5 GB volume |
| Simultaneous connections per account | 10 without a subscription, 50 with one | MySQL's default setting |
| New connections per hour per account | 600 | no limit |
The 600-connections-per-hour limit of a managed database counts connection openings, not queries. An application that opens a connection per request reaches it quickly: keep a pool open.
Connection string
# Managed database: the URI is shown at creation, with the password
DATABASE_URL=mysql://wg_ab12cd_blog:MOT_DE_PASSE@HOTE:3306/wg_ab12cd_blog?ssl-mode=REQUIRED
# Project database: full string in the service's Database tab
DATABASE_URL=mysql://kxuser:MOT_DE_PASSE@ma-db.kx-blog-1a2b3c4d.svc.cluster.local:3306/ma-db
A managed database's password is shown only once. If it is lost, Rotate password in the Accounts section generates another.
On a project database, the root account has the same password as kxuser. Keep kxuser for the application.
Laravel
DB_CONNECTION=mysql
DB_HOST=ma-db.kx-blog-1a2b3c4d.svc.cluster.local
DB_PORT=3306
DB_DATABASE=ma-db
DB_USERNAME=kxuser
DB_PASSWORD=MOT_DE_PASSE
php artisan migrate --force
--force is required outside the local environment. Run this command at startup or in the terminal, never during the build: the build has no access to the database.
WordPress
WORDPRESS_DB_HOST=ma-db.kx-blog-1a2b3c4d.svc.cluster.local:3306
WORDPRESS_DB_NAME=ma-db
WORDPRESS_DB_USER=kxuser
WORDPRESS_DB_PASSWORD=MOT_DE_PASSE
Media uploaded to WordPress must live on a volume mounted on wp-content/uploads, otherwise they disappear at the next restart.
Node.js (mysql2)
import mysql from "mysql2/promise";
const pool = mysql.createPool({ uri: process.env.DATABASE_URL, connectionLimit: 10 });
const [rows] = await pool.query("SELECT 1");
Python (SQLAlchemy and PyMySQL)
import os
from sqlalchemy import create_engine, text
# mysql:// becomes mysql+pymysql://
url = os.environ["DATABASE_URL"].replace("mysql://", "mysql+pymysql://", 1)
engine = create_engine(url, pool_size=5, pool_recycle=280)
with engine.connect() as conn:
print(conn.execute(text("SELECT 1")).scalar())
Connect from your machine
Managed database: add your address in Network access (My address button), then:
mysql --ssl-mode=REQUIRED -h HOTE -P 3306 -u USER -p BASE
Project database: turn on Public access in the Database tab and use the public host and port shown. Turn the access off after the intervention, this port is open to the whole Internet.
Queries from the panel
For a managed database, the Data tab shows the tables, the structure, the indexes and an SQL console (1,000 rows per result). For a project database, the console in the Database tab runs the query with the mysql client, stops it after 30 seconds, and suggests SHOW TABLES; by default.
Back up and import
# Export
mysqldump --ssl-mode=REQUIRED --single-transaction -h HOTE -P 3306 -u USER -p BASE > sauvegarde.sql
# Import
mysql --ssl-mode=REQUIRED -h HOTE -P 3306 -u USER -p BASE < sauvegarde.sql
--single-transaction exports a consistent view of InnoDB tables without locking them. The Data tab of a managed database imports an SQL or CSV file of up to 64 MB. The Backups tab of a project database schedules dumps (Backups and restore).
Limits to know
- On a managed database, your account has all rights on its database and none elsewhere. It creates neither a database nor a user: additional accounts are created in the Accounts section.
- A project database runs as a single instance, with at most 1 vCPU and 1 GB of memory.
- Use
utf8mb4for any new table. MySQL's oldutf8does not store 4-byte characters, emojis included.
Common errors
| Message | Cause | What to do |
|---|---|---|
Connections using insecure transport are prohibited | connection without TLS to a managed database | add ?ssl-mode=REQUIRED or the driver's SSL option |
User ... has exceeded the 'max_user_connections' resource | simultaneous connection limit reached | reduce the pool |
User ... has exceeded the 'max_connections_per_hour' resource | more than 600 connection openings in the hour | keep a pool open instead of opening a connection per request |
Access denied for user | stale password after a rotation | update the connection variable |
Unknown MySQL server host | internal address used outside the project | use public access or a managed database |
Incorrect string value: '\xF0\x9F...' | table in utf8 or latin1 | convert the table to utf8mb4 |
Moving a project MySQL database to a managed database is described on Databases.
Updated on