MySQL Shell for VS Code: Manage Databases and Create ‘Pro’ ERDs Like Workbench Directly in Your Editor

MySQL tutorial - IT technology blog
MySQL tutorial - IT technology blog

Why Should You Bring MySQL Directly Into VS Code?

If you’re working in Web or Backend development, you’re likely familiar with a screen cluttered with windows. On one side is VS Code for coding, and on the other is MySQL Workbench or DBeaver for checking data. Every time you Alt+Tab to copy-paste a query, your focus slips away. Not to mention, running another heavy Java app can consume an extra 500MB of RAM, causing lag while you have dozens of Chrome tabs open.

I once managed an e-commerce system running MySQL 8.0 with a database of about 50GB. Previously, every time I needed to debug, I had to open Workbench, wait for it to load, and then start querying. Since Oracle released MySQL Shell for VS Code, I’ve completely ditched those separate tools. Everything from writing queries and viewing table structures to drawing ERDs is now integrated into a single interface.

This extension is more than just a typical SQL client. It combines the power of MySQL Shell (supporting SQL, Python, and JavaScript) with the flexibility of VS Code. You can save scripts as Notebooks, which is incredibly useful for reports or writing documentation for the DevOps team.

Installation and Initial Connection Setup

To get started, open the Extensions view (Ctrl+Shift+X), search for “MySQL Shell for VS Code” and click Install. Opt for the official version from Oracle to ensure maximum stability and security.

Step 1: Connecting to the Server

Once installed, you’ll see a MySQL icon in the Activity Bar on the left. Click it and select “Add Connection”.

# Parameters to prepare:
Hostname: localhost (or server IP)
Port: 3306
User: root
Password: ********

When working with remote servers, this extension supports SSH Tunneling very smoothly. I often use it to connect directly to internal databases without opening port 3306 to the public Internet. This is both convenient and ensures maximum security for project data.

Using Notebooks: A Smarter Way to Work

Notebooks are the most valuable feature of this extension. Instead of typing into a plain .sql file, you can create a MySQL Shell Notebook (with a .mynb extension). It works similarly to Jupyter Notebooks in the world of Data Science.

Why are Notebooks so powerful?

  • Multi-language: Freely switch between SQL, JavaScript, and Python within the same file.
  • Visual: Query results appear directly below the code cell. You can export to JSON or CSV with a single click.
  • Markdown Notes: Explain complex query logic right on the spot so your colleagues can understand it instantly.

For example, when I need to filter the top 10 highest-spending customers in a 50GB database, I write the following:

-- Get VIP customer list
SELECT 
    u.username, 
    SUM(o.total_amount) as total_spent
FROM users u
JOIN orders o ON u.id = o.user_id
GROUP BY u.id
ORDER BY total_spent DESC
LIMIT 10;

The data table will appear neatly right below. Want to use these results for logic processing in Python? Just switch the mode to Python and call the last_result variable. Everything happens seamlessly without manual export/import.

Designing and Viewing ERDs (Entity Relationship Diagrams)

Many people stick with MySQL Workbench solely for its ERD drawing capabilities. However, MySQL Shell for VS Code handles this even faster and smoother.

After connecting, simply right-click a Schema and select “Add to Dashboard”. From there, choose the ER Diagram feature. The system will automatically scan Foreign Keys to map out the relationships between tables.

In my experience with systems containing hundreds of tables: don’t try to draw everything on one screen. This extension allows you to select specific groups of tables to create sub-diagrams. This helps the team visualize data flows without being overwhelmed by a matrix of overlapping relationships.

Optimizing Your Development Workflow

Since I started using this extension, my workflow has changed significantly. Instead of sending SQL files via Slack, I push .mynb files directly into the project’s Git repository.

Whenever there’s a new migration or a query needs optimization, I create a detailed Notebook describing:

  1. Bottlenecks in the old query (with execution plan screenshots).
  2. How the new query has been optimized.
  3. Actual benchmark results on the staging environment.

This approach is much more professional than just tossing around a random snippet of SQL code. For DevOps projects, this helps manage database infrastructure in a modern, code-centric style.

A small tip for you:

If your database has millions of rows, go to Settings and limit the number of records returned (the default is 1000). This prevents VS Code from hanging if you accidentally run a SELECT * on a massive table.

Conclusion

Bringing MySQL Shell into VS Code isn’t just about convenience. It helps synchronize your thinking between writing code and managing data. You’ll notice a significant increase in speed when all your tools are right at your fingertips.

If you’re still using separate tools, take 15 minutes to try out this extension. It will definitely make your database workflow much more enjoyable. Good luck with your database optimization!

Share: