Install MySQL 8.4 and Run Your First Query
You can follow most of this tutorial in the browser with the Try it buttons, but every SQL developer needs a real database server. This lesson shows the quickest way to install MySQL 8.4 LTS on Windows, macOS, Linux or Docker, how to connect to it, and how to load the sample company database used in every lesson.
- Choose the right MySQL version and package
- Install MySQL on Windows, macOS, Linux or with Docker
- Connect with the mysql command-line client and MySQL Workbench
- Create the sample database and run a first query
Which MySQL version?
Install MySQL 8.4 LTS (Long-Term Support). LTS releases get bug and security fixes for years without changing behaviour, which is what you want for learning and for production. The “Innovation” releases (9.x) add new features faster but are supported only until the next release. All queries in this tutorial were run on MySQL 8.4.
MySQL Community Server is free. Download it only from the official site, dev.mysql.com/downloads, or from your operating system’s package manager.
Install on Windows
- Download the MSI installer for MySQL Community Server 8.4 (Windows x86, 64-bit) from dev.mysql.com/downloads/mysql/.
- Run it and choose the Typical setup.
- At the end, the MySQL Configurator opens. Keep the defaults (Development Computer, port 3306), set a strong root password, and let it install MySQL as a Windows service.
- Optionally install MySQL Workbench (a graphical editor) from dev.mysql.com/downloads/workbench/.
Check the install from a new Command Prompt:
mysql --versionmysql -u root -pIf Windows says mysql is not recognized, add C:\Program Files\MySQL\MySQL Server 8.4\bin to your PATH, or open the MySQL 8.4 Command Line Client from the Start menu.
Install on macOS
Either download the DMG archive for macOS from dev.mysql.com and run the installer, or use Homebrew:
brew install mysql@8.4brew services start mysql@8.4mysql_secure_installationmysql_secure_installation sets the root password and removes the test database and anonymous users.
Install on Linux (Ubuntu / Debian)
sudo apt updatesudo apt install mysql-serversudo systemctl status mysqlsudo mysqlUbuntu’s own package may be an older 8.0 release. For 8.4, first add the official MySQL APT repository (the mysql-apt-config package from dev.mysql.com) and choose mysql-8.4-lts when it asks.
Run MySQL in Docker
If you already use Docker, this is the fastest clean install, and it is easy to throw away:
docker run --name mysql84 -e MYSQL_ROOT_PASSWORD=Learn_SQL_2026 -p 3306:3306 -d mysql:8.4docker exec -it mysql84 mysql -u root -pConnect and check the server
Once you are at the mysql> prompt (or in a Workbench query tab), ask the server which version it runs:
SELECT VERSION();| VERSION() |
|---|
| 8.4.13 |
VERSION()is a built-in function that returns the server version as text.- There is no
FROM, so MySQL evaluates the function once and returns one row.
List the databases on the server:
SHOW DATABASES;| Database |
|---|
| company |
| information_schema |
| mysql |
| performance_schema |
| sys |
SHOW DATABASESlists every database your account can see.information_schema,mysql,performance_schemaandsysare system databases. Do not create tables in them.companyis the sample database used in this tutorial (you create it in the next section).
Load the sample database
Every lesson uses the same small company database: departments, employees, customers, products, orders and order items. The Sample Database lesson lists all its rows and has the full script to copy. In short:
CREATE DATABASE company;USE company;-- then paste the CREATE TABLE and INSERT statements from the Sample Database lessonCheck that it worked:
SELECT COUNT(*) AS employees FROM employees;| employees |
|---|
| 12 |
COUNT(*)counts rows. You will learn it in Aggregate Functions.- The sample database has 12 employees, so the result is one row with the value 12.
mysql client commands you will use
| Command | What it does |
|---|---|
mysql -u root -p | Connect as root; it asks for the password |
SHOW DATABASES; | List databases |
USE company; | Make company the current database |
SHOW TABLES; | List tables in the current database |
DESCRIBE employees; | Show a table’s columns and types |
SOURCE C:/path/company.sql | Run every statement in a script file |
exit | Leave the client |
Quick quiz
1. Which MySQL release type should a beginner install?
LTS releases are supported for years and do not change behaviour between updates.
2. What does USE company; do?
After USE, unqualified table names refer to tables in company.
3. Which of these is a system database you should not put your tables in?
mysql, sys, information_schema and performance_schema belong to the server itself.
Installation FAQ
Is MySQL free?
Yes. MySQL Community Server is open source and free for learning and most commercial use. Oracle also sells an Enterprise edition with extra tools and support.
What is the default MySQL port?
- If another program already uses it, choose a different port during setup and connect with
mysql -u root -p -P 3307.
I forgot the MySQL root password. What now?
Stop the server, start it once with the --skip-grant-tables option, connect without a password and set a new one with ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';, then restart normally. On a fresh learning install it is often quicker to reinstall.
Should I use MySQL Workbench or the command line?
Learn both. Workbench is comfortable for writing and saving queries and shows results in a grid. The command-line client is available on every server and is what you will use over SSH.
Can I learn SQL without installing anything?
Yes. Every lesson here has Try it buttons that run the queries in your browser. Install MySQL when you want to build your own databases.