How to Quickly Set Up MySQL with Docker Desktop and Manage Your Database Structures

Looking for a an easy way to work with a MySQL database?

In this article, we’ll describe how to:

  • Set up MySQL database using Docker Desktop
  • Create a data model for your database in Luna Modeler
  • Generate SQL scripts from your data model
  • Run the scripts in VS Code with the MySQL Extension
  • Compare and synchronize your data model with the database

How to Run MySQL in Docker
and Create Your Database Visually

In the next section, we’ll show you how to set up a MySQL database using Docker Desktop. Then, you’ll learn how to work with your database using visual tools.

Step 1: Install Docker Desktop

To start, download and install Docker Desktop for your system – Windows, macOS, or Linux.
Once installed, open it.

Step 2: Find the mySQL Image and Run a Container

Navigate to the Images tab and click the Search icon.

Docker Desktop showing the Images tab and the Search button in the top panel.

Search for “mysql” and click the Run button.

Search for a mysql image in the Docker Desktop tool.

A new form opens. Define the Container name, Host ports (the default for MySQL are 3306 and for newer versions also 33060). Add a new environment variable MYSQL_ROOT_PASSWORD and type in the Value (this will be the password for the root user to the MySQL database). Then click Run.

Optional settings defined for MySQL container in Docker Desktop

If you look in the Containers section, you should see the running container.

MySQL container running in Docker Desktop.

The database is now up and running. Let’s proceed with the creation of a data model.

Step 3: Create your data model

Download and install Luna Modeler.

Create a new MySQL project and start designing your database structure visually: add tables, define columns, relationships, add notes and subject areas, and more. It is possible to model all aspects of the system without connecting to a database at this time.

A data model create for MySQL in Luna Modeler - data modeling tool.

Download Luna Modeler

Step 4: Generate SQL Script from Your Data Model

Once your data model is ready: Just click the SQL Script button. Take a look at the auto-generated SQL script and save it to your computer or copy it to the clipboard.

A screenshot of Luna Modeler, showing a form with generated SQL Script for MySQL

Step 5: Run the SQL Script in VS Code

Install and launch VS Code, then add the MySQL Shell for VS Code extension to it.

VS Code and search for MySQL extension.

Click on the newly added icon on the left. Then click on New Connection in the MySQL Shell tab.

A screenshot of VS Code showing how to define a new database connection to MySQL.

Specify connection properties.

New MySQL connection properties defined in VS Code and the MySQL Shell for VS Code extension.

After successfully connecting to the database, enter a command in DB Notebook to create a new database. In our case, it will be the ecommerce database. Also enter a script to use the database as the default. SQL:

CREATE DATABASE ecommerce;
USE ecommerce;

Run these commands and then insert or paste the SQL script generated from Luna Modeler.

A screenshot showing VS Code with SQL Scripts for MySQL

Result of the executed SQL script:

Execution of SQL script for MySQL. The screenshot shows VS Code.

Step 6: Make Changes to Your Data Model

Your system is going to keep evolving! And in the early stages of development, changes are not just expected – they’re essential! That’s why it’s so helpful to go back to Luna Modeler regularly to adjust your model: add new tables, modify columns, change data types, define relationships, or update constraints.

Tip: You can establish a connection to the database and update your data model in Luna Modeler. This will add the default settings like collation and others to the data model.

Step 7: Generate Sync Script

In Luna Modeler, click the Advanced button and choose the Generate Synchronization SQL item.

A screenshot of the Main toolbar that is available in Luna Modeler data modeling tool. The Advanced button expands a sub-menu with the Generate Synchronization SQL item.

Compare the data model to the database and generate SQL Script for the detected differences.

Synchronization SQL scripts generated for MySQL. The screenshot show the script generated by Luna Modeler.

Step 8: Run the generated Synchronization SQL script in VS Code

Paste the generated code to VS Code and execute the synchronization scripts.

How to execute synchronization SQL scripts for MySQL in VS Code.

Key Benefits of This Visual Workflow

  • Work offline on your model – Design first, deploy when ready
  • Reliable and repeatable SQL generation – Generate and run SQL only when your model is complete
  • Easy model-to-database synchronization – Quickly update your live database with visual changes

Get Started – Try Luna Modeler

Download Luna Modeler

#

DATA MODELING TOOLS
DRAW Diagrams and
GENERATE Scripts
Download data modeling tools
Blog Categories
Blog by Platforms