The golden rules
- Do not expose it. The MySQL (3306) or PostgreSQL (5432) port must not be open to the whole internet. Have it listen on localhost or a private network.
- One user per application with only the permissions it needs, never the administrator user.
- Long, unique passwords, kept in environment variables.
- Automatic backups kept off the server, and a restore test.
The steps, in short
- Install or subscribe to the database and create your app’s database and user.
- Restrict access: closed firewall for the database port and connections over localhost, a private network or a VPN.
- Automate backups with
mysqldumporpg_dumpin a scheduled task, compressed and with the date in the file name. - Send a copy off the server (a storage bucket, for example).
- Test restoring in another environment. A backup you never restored is a hope, not a backup.
- Monitor disk space and connections so you find out before it fills up.
- Apply migrations carefully: a backup first, then the change.
Common mistakes
- Leaving the database open to the internet with a weak password.
- Backing up onto the server’s own disk: if the disk fails, you lose everything.
- Using the database
rootuser from the application. - Running destructive migrations in production without testing first.
How we help
We leave your database private, with least-privilege users, automatic backups off the server and a tested restore.