Setting Up a Local MySQL Database with Docker
If you want to work with a database locally, you first need a database instance that you can connect to and work with.
For this setup, we’ll use MySQL 8 running in Docker. Docker keeps the database isolated from your local system and makes it easy to start and stop the environment whenever you need it.
Once MySQL is running, we’ll connect it to DevScribe’s Database Doc Tool.
Prerequisites
Before you begin, make sure you have:
- DevScribe installed and running
- Docker Desktop installed and running
- Docker Compose available through Docker Desktop
Create the Docker Compose Configuration
Start by creating a Docker Compose file in your DevScribe workspace.
For this example, we’ll create a MySQL service with the following configuration:
services:
mysql:
image: mysql:8
container_name: quickcart-mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: quickcart
ports:
- "3308:3306"Here’s what the main configuration options do:
| Configuration | Purpose |
|---|---|
image | Specifies the MySQL version to use |
container_name | Gives the container a recognizable name |
MYSQL_ROOT_PASSWORD | Sets the root password for the local database |
MYSQL_DATABASE | Creates the quickcart database |
ports | Makes MySQL available through port 3308 on the host |
Note: The credentials used here are for a local demonstration environment. For production environments, use secure credentials and appropriate secret management.
Start MySQL
With the Compose file ready, use Up in the Docker Compose workspace to start the service.
DevScribe runs the Compose configuration and creates the MySQL container.
Once the process finishes, the console should indicate that the Docker Compose configuration was executed successfully.
The MySQL service is now running and can be accessed through the port we exposed in the Compose configuration.
In this setup:
localhost:3308 → MySQL:33063308 is the port we’ll use when connecting to MySQL from the host machine. Inside the container, MySQL continues to use its default port, 3306.
Check That the Container Is Running
You can confirm that the MySQL container is running from a terminal with:
docker psLook for the quickcart-mysql container in the list of running containers.
If the container appears with an Up status, MySQL is running and ready for the next step.
Connect MySQL to DevScribe
Now that the database is running, open the Database Doc Tool in DevScribe and add a new database connection.
Select MySQL and enter the connection details that correspond to the Docker configuration:
| Configuration | Value |
|---|---|
| Host | localhost |
| Port | 3308 |
| Database | quickcart |
| Username | root |
| Password | root |
The host and port tell DevScribe where the MySQL server is running, while the database and credentials specify which database and user to connect with.
Select Connect to establish the connection.
Verify the Connection
Once the connection is successful, the database will be available in the Database workspace.
Expand the connection to view the quickcart database and its available resources.
[Screenshot: Connected quickcart database]
Your local MySQL environment is now ready to use from DevScribe.
From here, you can create database resources and start working with queries directly in the Database Doc Tool.
Here’s a walk through:
What’s next?
Now that the database is connected, you can start working with the data.
See Executing Database Queries in DevScribe to learn how to create a query, run it against your connected database, and view the results.