# MySQL

Learn how to use MySQL databases with Hatchbox

Hatchbox supports two types of MySQL services: managed and unmanaged.

- Managed MySQL runs on a service like DigitalOcean, PlanetScale, Amazon RDS, etc
- Unmanaged MySQL runs on a server inside your Hatchbox cluster (for free!)

## Managed MySQL

To use a managed MySQL database with Hatchbox:

- Create the database on your provider of choice
- Add an environment variable to your app to connect to your database. Typically, `DATABASE_URL` for Ruby applications.

Backups, upgrades and maintenance is handled by your MySQL provider.

## Unmanaged MySQL

Choose a server in your cluster and assign it the MySQL role. This will install the MySQL server package and allow you to create databases in Hatchbox.

#### Connecting to MySQL databases remotely

If you&#39;d like to connect to your MySQL database from your local machine, you will need to use an SSH tunnel.

Let&#39;s use TablePlus for example:

1. Under &quot;Over SSH&quot;, add your server&#39;s public IP address and the &quot;deploy&quot; user.
2. Check the &quot;Use SSH key&quot; box. Optionally, import your private key if you don&#39;t have it in your SSH config.
3. Set the database host to &quot;127.0.0.1&quot; since you&#39;ll be connected over SSH.
4. Set the username and password for your Hatchbox database.
5. Test the connection to confirm everything works.
