SQL Tutorial › Getting Started › Install MySQL

Install MySQL 8.4 and Run Your First Query

BeginnerLesson 2 of 6912 min read3 queries run on MySQL 8.4

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.

Advertisement
In this 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.

Note

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

  1. Download the MSI installer for MySQL Community Server 8.4 (Windows x86, 64-bit) from dev.mysql.com/downloads/mysql/.
  2. Run it and choose the Typical setup.
  3. 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.
  4. Optionally install MySQL Workbench (a graphical editor) from dev.mysql.com/downloads/workbench/.

Check the install from a new Command Prompt:

Command Prompt
mysql --versionmysql -u root -p
Tip

If 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:

Terminal
brew install mysql@8.4brew services start mysql@8.4mysql_secure_installation

mysql_secure_installation sets the root password and removes the test database and anonymous users.

Install on Linux (Ubuntu / Debian)

Terminal
sudo apt updatesudo apt install mysql-serversudo systemctl status mysqlsudo mysql

Ubuntu’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:

Terminal
docker run --name mysql84 -e MYSQL_ROOT_PASSWORD=Learn_SQL_2026 -p 3306:3306 -d mysql:8.4docker exec -it mysql84 mysql -u root -p

Connect and check the server

Once you are at the mysql> prompt (or in a Workbench query tab), ask the server which version it runs:

MySQL
SELECT VERSION();
ResultMySQL 8.4
VERSION()
8.4.13
1 row in set
How this query works, step by step
  1. VERSION() is a built-in function that returns the server version as text.
  2. There is no FROM, so MySQL evaluates the function once and returns one row.

List the databases on the server:

MySQL
SHOW DATABASES;
ResultMySQL 8.4
Database
company
information_schema
mysql
performance_schema
sys
5 rows in set
How this query works, step by step
  1. SHOW DATABASES lists every database your account can see.
  2. information_schema, mysql, performance_schema and sys are system databases. Do not create tables in them.
  3. company is 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:

MySQL
CREATE DATABASE company;USE company;-- then paste the CREATE TABLE and INSERT statements from the Sample Database lesson

Check that it worked:

SQL
SELECT COUNT(*) AS employees FROM employees;
ResultMySQL 8.4
employees
12
1 row in set
How this query works, step by step
  1. COUNT(*) counts rows. You will learn it in Aggregate Functions.
  2. The sample database has 12 employees, so the result is one row with the value 12.

mysql client commands you will use

CommandWhat it does
mysql -u root -pConnect 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.sqlRun every statement in a script file
exitLeave the client

Quick quiz

1. Which MySQL release type should a beginner install?

2. What does USE company; do?

3. Which of these is a system database you should not put your tables in?

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?
  1. 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.