MySQLMySQL Workbench

MySQL Workbench

MySQL Workbench is the official GUI tool for MySQL, developed and maintained by Oracle. It combines a visual SQL editor, schema design canvas, server administration panel, and data import/export wizard into a single application. Workbench is free and runs on Windows, macOS, and Linux.

Whether you are writing your first query or designing a complex normalized schema, Workbench provides a productive visual environment that complements the command-line client.

Installing MySQL Workbench

Windows and macOS: Download the installer from dev.mysql.com/downloads/workbench/. Run the installer and follow the wizard — no special configuration is needed.

Ubuntu / Debian:

Bash
# Install from Ubuntu's universe repository
sudo apt update
sudo apt install mysql-workbench-community -y

# Or download the .deb package from dev.mysql.com for the latest version
# then install it:
sudo dpkg -i mysql-workbench-community_8.0.36-1ubuntu22.04_amd64.deb
sudo apt install -f   # resolve any dependency issues
Note
Workbench requires a 64-bit OS. On Linux it depends on GTK and several system libraries — the apt install -f step installs missing dependencies automatically.
Connecting to a MySQL Server

When you launch Workbench, the home screen shows your saved connections. To add a new one:

  1. Click the "+" button next to "MySQL Connections" on the home screen.

  2. Give the connection a name (e.g., "Local Dev" or "Production Read Replica").

  3. Set Connection Method to "Standard (TCP/IP)" for most connections.

  4. Enter Hostname (127.0.0.1 for local), Port (3306 is default), and Username (root or your app user).

  5. Click "Store in Keychain" (macOS) or "Store in Vault" (Windows/Linux) to save the password securely.

  6. Click "Test Connection" to verify — a green checkmark means success.

  7. Click OK to save, then double-click the connection card to open it.

Connection types available:

Method

Use Case

Standard TCP/IP

Direct connection to a MySQL server by hostname and port

Local Socket/Pipe

Connect via Unix socket (faster than TCP for localhost on Linux/macOS)

Standard TCP/IP over SSH

Tunnel the MySQL connection through an SSH server — ideal for connecting to production databases securely

Tip
For connecting to a remote production database, always use "Standard TCP/IP over SSH" rather than exposing MySQL port 3306 to the internet. Set your SSH host, SSH username, and SSH key/password, then your MySQL credentials — Workbench handles the tunnel automatically.
The Workbench Interface

After connecting, Workbench opens the main editor. The interface has several key areas:

Navigator Panel (Left Sidebar)
  • Schemas tab: Browse all databases on the server. Expand a schema to see Tables, Views, Stored Procedures, and Functions. Right-click any object for a context menu of actions.

  • Administration tab: Access server status, user accounts, import/export wizard, and configuration variables. This is the GUI equivalent of running SHOW STATUS or editing my.cnf.

Query Editor (Center)

The query editor is where you write and run SQL. Key features:

  • Syntax highlighting: SQL keywords, table names, and strings are color-coded.

  • Auto-complete: Press Ctrl+Space to trigger suggestions for table names, column names, and SQL keywords.

  • Multiple tabs: Open multiple query tabs with Ctrl+T (or Cmd+T on macOS). Each tab has its own connection session.

  • Execute buttons: The lightning bolt icon runs the entire script; the lightning bolt with a cursor runs only the statement under the cursor.

  • Keyboard shortcuts: Ctrl+Enter (or Cmd+Enter) executes the current statement. Ctrl+Shift+Enter runs the entire script.

Results Grid (Bottom)

Query results appear in a tabular grid. You can:

  • Sort results by clicking column headers

  • Edit cell values directly in the grid and apply changes (for simple single-table SELECT queries)

  • Export results to CSV, JSON, or HTML using the Export button

  • View the execution plan and query statistics in the "Execution Plan" and "Query Stats" tabs

Output Panel

The output panel at the bottom shows the execution log: which queries ran, how long they took, affected row counts, and any errors or warnings. This is invaluable for debugging.

Running Queries in Workbench

SQL
-- Select the database you want to work with
USE sakila;

-- Basic query — Workbench highlights the statement, press Ctrl+Enter to run it
SELECT actor_id, first_name, last_name
FROM actor
ORDER BY last_name
LIMIT 10;

-- Run multiple statements — select all, then Ctrl+Shift+Enter
CREATE TABLE test_table (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO test_table (name) VALUES ('Alice'), ('Bob'), ('Carol');

SELECT * FROM test_table;
Tip
Right-click any table name in the Navigator and choose "Select Rows — Limit 1000" to instantly run a SELECT query against that table. This is the fastest way to preview table contents without typing.
Using the EER Diagram Tool

The EER (Enhanced Entity-Relationship) diagram tool lets you visually design or reverse-engineer your database schema. To reverse-engineer an existing schema into a diagram:

  1. Go to Database menu → Reverse Engineer

  2. Select your connection and click Continue

  3. Choose the schema (database) to import

  4. Workbench reads all table definitions and generates a visual diagram

  5. Tables appear as boxes; foreign key relationships are drawn as lines with crow's foot notation

To create a new schema visually:

  1. Go to File → New Model

  2. Double-click "Add Diagram" to open the canvas

  3. Drag a Table object from the toolbar onto the canvas

  4. Double-click the table to edit columns, types, and constraints

  5. Use the "1:N Relationship" tool to draw foreign key lines between tables

  6. When done, go to Database → Forward Engineer to generate and execute the CREATE TABLE statements

Note
Forward engineering validates your diagram before generating SQL — it will catch missing primary keys, unsupported data types, and naming conflicts. This makes it an excellent tool for schema review before deploying to production.
Importing and Exporting Data
Import via Wizard

To import a SQL dump file (e.g., a sample database or production backup):

  1. Go to Server → Data Import

  2. Choose "Import from Self-Contained File" and browse to the .sql file

  3. Select a target schema or create a new one

  4. Click "Start Import"

  5. Check the Import Progress tab for completion status and errors

Export via Wizard
  1. Go to Server → Data Export

  2. Check the schemas and tables you want to export

  3. Choose "Export to Self-Contained File" for a single .sql file

  4. Configure options: include CREATE TABLE, include data (INSERT statements), and whether to add DROP TABLE IF EXISTS

  5. Click "Start Export"

Warning
The Workbench export wizard is suitable for small-to-medium databases. For large databases (over a few GB), use mysqldump from the command line — it is faster, handles errors better, and supports streaming to compressed files.
Viewing the Query Execution Plan

One of Workbench's most powerful features for performance optimization is the visual execution plan. After running a query, click the "Execution Plan" tab in the results panel.

Workbench displays a flowchart of how MySQL executed the query: which indexes were used, how many rows were examined, and where the cost was spent. Red nodes indicate expensive full table scans. This is a visual wrapper around the EXPLAIN command.

SQL
-- You can also run EXPLAIN directly in the editor
EXPLAIN SELECT c.customer_id, c.first_name, COUNT(r.rental_id) AS rental_count
FROM customer c
JOIN rental r ON c.customer_id = r.customer_id
WHERE c.store_id = 1
GROUP BY c.customer_id
ORDER BY rental_count DESC;
Tip
Look for "Full Table Scan" (type = ALL in EXPLAIN output) on large tables — these are query performance killers. Add an index on the column in the WHERE clause and re-run EXPLAIN to verify MySQL uses it.
Managing Users and Privileges

The Administration tab in the Navigator provides a GUI for user management:

  • Navigate to Administration → Users and Privileges

  • The left panel lists all MySQL users. Click a user to see their roles and schema privileges

  • Use "Add Account" to create a new user — set login name, host, authentication type, and password

  • The "Schema Privileges" tab lets you grant or revoke privileges on specific databases

  • The "Administrative Roles" tab assigns server-level roles like DBA, MonitorAdmin, or BackupAdmin

Workbench Keyboard Shortcuts

Shortcut (Windows/Linux)

Shortcut (macOS)

Action

Ctrl+Enter

Cmd+Enter

Execute current statement

Ctrl+Shift+Enter

Cmd+Shift+Enter

Execute all statements in tab

Ctrl+T

Cmd+T

New query tab

Ctrl+W

Cmd+W

Close current tab

Ctrl+Space

Ctrl+Space

Trigger autocomplete

Ctrl+/

Cmd+/

Toggle comment on selected lines

Ctrl+B

Cmd+B

Auto-format (beautify) SQL

F2

F2

Rename selected object in Navigator

Workbench vs Command Line

Workbench and the mysql CLI are complementary tools. Use each where it excels:

Task

Recommended Tool

Browsing schema and table structure

Workbench (visual Navigator)

Writing and testing ad-hoc queries

Either (Workbench has autocomplete)

Viewing query execution plans visually

Workbench

Designing schemas with ER diagrams

Workbench

Running SQL scripts in CI/CD pipelines

mysql CLI

Large imports/exports

mysqldump / mysql CLI (faster)

Remote server administration via SSH

mysql CLI or Workbench SSH tunnel

Automation and scripting

mysql CLI

Note
Workbench is a development and administration tool — it connects directly to MySQL. In production environments, never leave Workbench connected to the production write server with root credentials. Use read-replica connections with limited privileges for safe exploration of production data.