Himanshu SharmaSoftware engineer
Let’s talk

MySQL · Lesson 2 of 50

Install MySQL

Install MySQL Server 8.4 on Windows, macOS, Linux or Docker, secure the root account and check that the server is running, with every command explained.

15 minGetting startedUpdated 22 October 2026

Awaiting technical review. This lesson is readable but not yet listed in search engines.

By the end of this lessonInstall a MySQL server on your own computer and confirm that it is running and that you can reach it.

Choose one route

MySQL Community Edition is free. You only need one of the routes below. All of them end in the same place: a server process running on your machine, listening on port 3306.

This course uses MySQL 8.4 LTS. A long-term support (LTS) release gets bug and security fixes for years, which makes it a sensible version to learn on. Newer "innovation" releases also exist; the lessons here run on them as well, except where a lesson says otherwise.

Windows

  1. Download the MySQL Installer from the official MySQL downloads page (dev.mysql.com/downloads/).
  2. Run it and choose Server only (or "Developer Default" if you also want Workbench, the graphical client).
  3. When the installer asks for the root password, choose a strong one and write it down in a password manager. The Password Generator can make one.
  4. Leave "Start the MySQL Server at System Startup" ticked, and finish the wizard.

The installer registers MySQL as a Windows service, so it starts by itself after a reboot.

macOS

With Homebrew installed, one command does everything:

bash
brew install mysql@8.4
brew services start mysql@8.4

The second command starts the server now and again at login. Homebrew installs the programs into a folder that is not on your PATH by default. The install output prints the exact export PATH=... line to add to your shell profile so that the mysql command works. Alternatively, download the DMG installer from the MySQL downloads page and follow its steps.

Ubuntu and Debian

bash
sudo apt update
sudo apt install mysql-server
sudo systemctl status mysql

The last command shows whether the service is active (running). On these systems the root account usually authenticates through the operating system, so you connect with sudo mysql instead of a password.

Docker (any system)

If you have Docker, a throwaway server takes one line. It is also the cleanest way to experiment, because deleting the container deletes everything:

bash
docker run --name mysql-learn -e MYSQL_ROOT_PASSWORD=choose-a-password -p 3306:3306 -d mysql:8.4

--name labels the container, -e sets the root password, -p 3306:3306 makes the port reachable from your machine, and -d runs it in the background. Connect with docker exec -it mysql-learn mysql -uroot -p.

Secure the root account

A fresh install can have weak defaults. The bundled script walks you through the important ones:

bash
sudo mysql_secure_installation

It offers to set the root password, remove anonymous users, disallow remote root login and remove the test database. Answering "yes" to those is the right choice for a learning machine as well, because it builds good habits.

Remember the rule that matters most: root is for administration only. Real applications get their own limited user. The lesson on users and privileges shows how.

Check that it works

First check the client program exists:

bash
mysql --version

You should see a line such as mysql Ver 8.4.x. That tells you about the client. To see what the server is, connect and ask it (the next lesson shows how to connect):

sql
SELECT VERSION();

The answer depends on which server you installed. For a default install you will see a value starting with 8.4. If mysql --version works but the connection fails with "Can't connect to MySQL server", the server is not running or is listening somewhere else. Start the service (brew services start mysql@8.4, sudo systemctl start mysql, or the Windows Services panel) and try again.

Common mistakes

  • Installing two servers on port 3306. Only one program can listen on a port. If a second install fails to start, an older one is probably still running.
  • Losing the root password. Write it down at once. Resetting it is possible but fiddly.
  • Confusing the client and server versions. mysql --version reports the client. Use SELECT VERSION(); for the server.
  • Opening port 3306 to the whole internet. A database should be reachable only from your own machine or private network.

Exercise

Install MySQL using the route that suits your system, then answer: (1) which command proves the client is installed, (2) which port should the server be listening on, and (3) which statement tells you the server version once you are connected?

Show one possible answer
  1. mysql --version
  2. Port 3306 (unless you chose a different one during setup).
  3. SELECT VERSION();

Key points

  • Pick one install route: the MySQL Installer on Windows, Homebrew or the DMG on macOS, apt on Ubuntu or Debian, or Docker on any system.
  • The server (mysqld) must be running before any client can connect; the default port is 3306.
  • Set a strong root password and never use the root account for your applications. You will create limited users later.
  • Check the install with mysql --version for the client and SELECT VERSION(); for the server you are actually connected to.

Check yourself

1. Which TCP port does MySQL listen on by default?
2. What is the difference between mysql and mysqld?
3. Why should an application not connect as the root user?
4. Which command shows the version of the MySQL server you are connected to?