#Setting up MySQL properly from scratch, then connect it to VS Code so you can work like a developer.
We’ll go in this order:
- Install & open MySQL (Command Line)
- Set up MySQL properly (recommended configuration)
- Create a schema in MySQL Workbench
- Connect MySQL to VS Code
- Write and run SQL from VS Code
Download MySQL Community Server:
👉 https://dev.mysql.com/downloads/mysql/
During installation:
- Choose Developer Default
- Set a root password (SAVE THIS)
- Keep default port:
3306 - Leave authentication as default (recommended)
- Press
Win + R - Type:
cmdThen connect:
mysql -u root -pEnter your root password.
Open Terminal:
mysql -u root -pIf command not found:
/usr/local/mysql/bin/mysql -u root -pIf successful, you’ll see:
mysql>Now you're inside MySQL.
Configuration file:
- Windows:
C:\ProgramData\MySQL\MySQL Server 8.0\my.ini - macOS/Linux:
/etc/my.cnf
[mysqld]
port=3306
max_connections=200
innodb_buffer_pool_size=1G
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ciutf8mb4→ supports full Unicodeinnodb_buffer_pool_size→ improves performancemax_connections→ allows more users
After editing → restart MySQL service.
Install:
Open Workbench:
-
Click your local MySQL connection
-
On left panel → right-click Schemas
-
Click Create Schema
-
Name it (example:
school) -
Choose:
- Charset:
utf8mb4 - Collation:
utf8mb4_unicode_ci
- Charset:
-
Click Apply
To verify:
SHOW DATABASES;Install:
Then install extensions:
- SQLTools
- SQLTools MySQL/MariaDB Driver
- Open VS Code
- Press
Ctrl + Shift + P - Type:
SQLTools: Add New Connection
- Choose MySQL
- Enter:
| Setting | Value |
|---|---|
| Host | localhost |
| Port | 3306 |
| User | root |
| Password | your_password |
| Database | school (or leave empty) |
Click Test Connection Then Save
Create a file:
database.sql
Example:
CREATE DATABASE school;
USE school;
CREATE TABLE students (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100),
age INT
);Right-click → Run Query
For real development, don’t use root.
Instead create a developer user:
CREATE USER 'devuser'@'localhost' IDENTIFIED BY 'strongpassword';
GRANT ALL PRIVILEGES ON school.* TO 'devuser'@'localhost';
FLUSH PRIVILEGES;Then connect VS Code using devuser.
✔ MySQL Server installed ✔ utf8mb4 enabled ✔ MySQL Workbench for visual management ✔ VS Code + SQLTools for coding ✔ Separate developer user (not root)