Skip to main content
Version: v2.x

Getting Started with Hasura and MySQL in Docker

Available on: Enterprise (Self-hosted)


This guide will help you get set up with the Enterprise Edition of Hasura GraphQL Engine with our MySQL integration using Docker Compose. This is the easiest way to set up Hasura Enterprise Edition and the MySQL GraphQL Data Connector.

Supported versions:
  1. Hasura GraphQL Engine v2.19.0 onwards
  2. MySQL version 8.0 and higher
  3. Currently only standard implementations of MySQL are supported. PlanetScale and certain other providers are unsupported.
Alpha version supported features

Hasura currently supports queries, mutations (INSERT, UPDATE, DELETE), table relationships and permissions on MySQL.

Note that Hasura doesn't yet support the ability to modify the database schema for MySQL, so the database you connect to should already contain tables and data. You should also ideally have access to it outside of Hasura to modify the schema.

Deploying Hasura Enterprise with Docker


This tutorial assumes that the following prerequisites have been met:

  • To deploy Hasura EE, you will need a license key. Please contact Hasura Sales if you do not already have one.
  • You have Docker and Docker Compose working on your machine.
  • You have access to a MySQL database for which you would like to create an API.

Step 1: Get the Docker Compose file

The install manifests repo contains all installation manifests required to deploy Hasura anywhere. The Docker Compose manifest also contains a Postgres database in order to store the Hasura metadata and a Redis instance for caching.

# in a new directory run
# or run
curl -o docker-compose.yaml

Step 2: Set the Hasura EE license key and the admin secret

Edit the downloaded docker-compose.yaml and set the license key and admin secret.

An admin secret key is required to make sure that your GraphQL endpoint and the Hasura Console are not publicly accessible.

Edit the Docker Compose file to include the license key and admin secret environment variables

image: hasura/graphql-engine:v2.12.0
Secure the admin secret

The HASURA_GRAPHQL_ADMIN_SECRET should never be passed from the client to the Hasura GraphQL Engine as it would give the client full admin rights to your Hasura instance. See Authentication & Authorization for information on setting up auth in Hasura.

Step 3: Run Hasura GraphQL Engine

The following command will create and run the containers in the Docker Compose manifest:

docker compose up -d

Check that the containers are running:

docker ps

097f58433a2b hasura/graphql-engine ... 1m ago Up 1m 8080->8080/tcp ...
b0b1aac0508d postgres ... 1m ago Up 1m 5432/tcp ...
3a29aa348999 redis:7 ... 1m ago Up 1m 6379/tcp ...
7b5b2ee70ece hasura/graphql-data-connector ... 1m ago Up 1m 5005/tcp ..

Step 5: Load the Hasura Console

Open the Hasura Console by navigating to http://localhost:8080/console. You will need to input your admin secret key as set in your Docker Compose file to log in.

Step 6: Connect to a MySQL database

From the Console, click the Data tab:

Connect database

Select the MySQL (Alpha) data source driver, enter in a display name for the database and set the JDBC Connection URL for your MySQL instance.

The JDBC connection URL should look like this:

jdbc:mysql://<hostname>:<port>/<database name>?user=<username>&password=<password>

For example:

jdbc:mysql://  # assuming the default port 3306
jdbc:mysql://localhost:4533/mysqltest?user=abc&password=pqr # assuming MySQL is running on port 4533

For more information see MySQL Connection URL syntax.

Click Connect Database.

Step 7: Track tables and run GraphQL API queries

Now that you have successfully connected your MySQL database to Hasura, you can track tables and use Hasura to automatically build a full-featured GraphQL API for it.

Step 8 (optional): Use managed PostgreSQL and Redis instances

The Hasura EE Docker compose files come with containerized open-source versions of PostgreSQL and Redis.

We highly recommend using managed PostgreSQL and Redis instances especially when running in production.

To switch to using your PostgreSQL or Redis instances, set the following environment variables:


For example:

image: hasura/graphql-engine:v2.12.0
HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://postgres:[email protected]:5432/postgres
HASURA_GRAPHQL_REDIS_URL: 'redis://redis:6379'