Create Your First MySQL Connection in MySQL Workbench – Complete Beginner's Guide
Before you can create databases, tables, or run SQL queries, you must first establish a connection to your MySQL Server. A MySQL Connection acts as a bridge between MySQL Workbench and the MySQL Server running on your computer.
In this lesson, you will learn how to create your first MySQL connection, test it, troubleshoot common connection problems, and understand the connection settings you'll use throughout this FastAPI course.
What is a MySQL Connection?
A MySQL Connection is a configuration that allows MySQL Workbench (the client) to communicate with the MySQL Server (the database server).
A connection contains information such as:
Server Hostname
Port Number
Username
Password
Connection Name
Without a valid connection, MySQL Workbench cannot access your databases.
Why Do We Need a MySQL Connection?
Creating a connection allows you to:
Access the MySQL Server
Create databases
Create tables
Run SQL queries
Import and export data
Manage users
Configure server settings
Build FastAPI database applications
Prerequisites
Before creating your first connection, ensure that you have:
Windows 10 or Windows 11
MySQL Community Server installed
MySQL Workbench installed
A configured root user
The MySQL service running
Launch MySQL Workbench
Open the Start Menu.
Search for:
MySQL WorkbenchClick the application to open it.
After a few seconds, the MySQL Workbench home screen will appear.
Create a New Connection
On the Workbench home screen, locate the MySQL Connections section.
Click the + (Plus) icon.
A new connection window will appear.
Configure the Connection
Fill in the connection details as shown below.
Setting | Value |
|---|---|
Connection Name | Local MySQL |
Connection Method | Standard (TCP/IP) |
Hostname | localhost |
Port | 3306 |
Username | root |
Password | Leave empty for now |
These settings are suitable for most local development environments.
Save the Password
Next to the Password field, click:
Store in Vault...Enter your MySQL root password.
Click:
OKSaving the password is optional, but it allows Workbench to connect without asking for the password each time.
Test the Connection
Click:
Test ConnectionIf prompted, enter your root password.
If everything is configured correctly, you should see:
Successfully made the MySQL connection.Click:
OKSave the Connection
Click:
OKYour new connection will now appear on the Workbench home screen.
Example:
Local MySQLOpen the Connection
Double-click:
Local MySQLWorkbench will connect to the MySQL Server.
The SQL Editor window will open.
You are now connected to your database server.
Verify the Connection
Run the following SQL command:
SELECT VERSION();Click the Execute (⚡ Lightning Bolt) button.
Example output:
9.x.xThis confirms that Workbench is successfully communicating with the MySQL Server.
Check the Current User
Run:
SELECT CURRENT_USER();Example output:
root@localhostThis confirms that you are connected using the root account.
Show All Databases
Run:
SHOW DATABASES;Example output:
information_schema
mysql
performance_schema
sysIf the database list appears, your connection is working correctly.
Understanding Connection Settings
Connection Name
This is simply a friendly name shown inside MySQL Workbench.
Example:
Local MySQLConnection Method
For local development, always use:
Standard (TCP/IP)Hostname
For a local MySQL Server:
localhostor
127.0.0.1Port
The default MySQL port is:
3306Only change this if your MySQL Server was configured to use a different port.
Username
For this course:
rootLater, we'll create a dedicated user for FastAPI applications.
Password
Use the password you created during MySQL installation.
Common Connection Problems
Cannot Connect to MySQL Server
Verify:
MySQL Server is installed.
The MySQL service is running.
The hostname is correct.
Port 3306 is open.
Your password is correct.
Access Denied
Example:
Access denied for user 'root'@'localhost'Solution
Verify the username.
Check the password.
Ensure Caps Lock is disabled.
Unknown Host
Verify the hostname.
Use:
localhostinstead of an incorrect server name.
Connection Refused
Open Windows Services.
Verify that the MySQL service is running.
If it is stopped, start it.
Port Already in Use
If another application is using port 3306, either stop the conflicting application or configure MySQL to use another port.
Best Practices
Use meaningful connection names.
Store passwords securely.
Use localhost for local development.
Use dedicated database users for applications instead of the root account.
Keep MySQL Workbench updated.
Summary
Congratulations! You have successfully created your first MySQL connection.
Your MySQL Workbench is now connected to the MySQL Server, allowing you to create databases, execute SQL queries, and manage your data.
In the next lesson, we will create your first database (Schema) and learn how MySQL organizes data.
Frequently Asked Questions (FAQs)
What is a MySQL connection?
A MySQL connection allows MySQL Workbench to communicate with a MySQL Server.
What is the default MySQL port?
3306Can I have multiple MySQL connections?
Yes. You can create connections to different local or remote MySQL servers.
Can I connect to a remote server?
Yes. Replace localhost with the remote server's hostname or IP address, and use the correct username and password.
Official Download Links
MySQL Workbench: https://dev.mysql.com/downloads/workbench/
MySQL Documentation: https://dev.mysql.com/doc/workbench/en/
MySQL Community Server: https://dev.mysql.com/downloads/mysql/