Installing MySQL
Install MySQL Community Server on your computer and verify the installation using the command-line client.
Introduction
Before you can write a single SQL query, you need MySQL actually installed and running on your machine. Thankfully, MySQL Community Server is free, and the official installers make setup fairly painless on every major operating system.
This lesson walks through downloading and installing MySQL Community Server on Windows, macOS, and Linux, setting a root password, and verifying everything works using the command-line client.
- Where to download MySQL Community Server from the official source.
- How the MySQL Installer works on Windows.
- How to install MySQL on macOS and Linux.
- How to set and remember a root password during setup.
- How to verify your installation using the mysql command-line client.
- That XAMPP is a quick alternative that bundles MySQL/MariaDB.
Downloading MySQL Community Server
MySQL Community Server is the free edition of MySQL, and it is exactly what this course uses. Always download it from the official MySQL website rather than a third-party mirror.
Go to dev.mysql.com/downloads/mysql and choose "MySQL Community Server." The site automatically detects your operating system, but you can also manually select Windows, macOS, or Linux from the dropdown.
Installing on Windows
On Windows, MySQL provides a single tool called the MySQL Installer, which can install and manage the server, client tools, and even MySQL Workbench (covered in the next lesson) all in one place.
1️⃣ Download
Get "mysql-installer-community" (the full offline installer is more reliable than the web installer).
2️⃣ Choose Setup Type
Select "Developer Default" or "Server only" to install just what you need.
3️⃣ Configure
Follow the wizard to configure the server type, port (default 3306), and authentication.
4️⃣ Set Root Password
Choose and confirm a strong root password when prompted.
Once the wizard finishes, MySQL Server runs as a Windows service, meaning it can start automatically in the background whenever your computer boots.
Installing on macOS
On macOS, you can download a DMG package directly from the MySQL downloads page. Running it launches a standard macOS installer wizard.
# If you prefer Homebrew instead of the DMG installer:
brew install mysql
# Start the MySQL service:
brew services start mysqlWhichever method you choose, macOS also lets you set the root password either during the DMG installer's setup screen, or afterward using the mysql_secure_installation command-line tool.
Installing on Linux
On most Linux distributions, MySQL (or the MySQL APT/YUM repository) can be installed directly through the system package manager.
sudo apt update
sudo apt install mysql-server
# Start and enable the service:
sudo systemctl start mysql
sudo systemctl enable mysqlAfter installation, running the included security script helps lock down the default setup, including setting a root password.
sudo mysql_secure_installationSetting the Root Password
The "root" user is the default administrative account in MySQL, with full permission to do anything on the server. Whatever platform you install on, you will be asked to set a root password at some point during setup.
Write down or securely store your root password. You will need it every time you connect to MySQL from the command line or from MySQL Workbench in the next lesson.
Verifying the Installation
Once installed, the best way to confirm everything is working is to connect using the MySQL command-line client. Open a terminal (or Command Prompt on Windows) and run the following.
mysql -u root -pThis tells MySQL to connect as the user "root" (-u root) and to prompt you for a password (-p). Type the root password you set during installation and press Enter.
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.36 MySQL Community Server - GPL
mysql>Seeing the mysql> prompt means the installation succeeded and you are now connected to your MySQL server. You can quickly check the version to confirm which one you installed.
SELECT VERSION();+-----------+
| VERSION() |
+-----------+
| 8.0.36 |
+-----------+XAMPP as an Alternative
If you have taken the PHP course on this platform, you may already have XAMPP installed. XAMPP bundles Apache, PHP, and either MySQL or MariaDB together in one simple installer, which makes it a convenient quick-start option for local development.
If XAMPP is already installed, its bundled MySQL/MariaDB server can be used for this course too — just start "MySQL" from the XAMPP Control Panel and connect the same way, using the mysql command-line client or MySQL Workbench.
Common Mistakes
- Forgetting the root password set during installation, with no record of it anywhere.
- Downloading MySQL from an unofficial third-party site instead of dev.mysql.com.
- Not checking whether the MySQL service is actually running before trying to connect.
- Installing multiple database servers on the same default port (3306) without realizing it causes conflicts.
Best Practices
- Always download MySQL Community Server from the official dev.mysql.com site.
- Choose a root password you can securely store and recall for this course.
- Verify your installation immediately with `mysql -u root -p` before moving on.
- Keep note of your MySQL version, since some features in this course require MySQL 8.0+.
Frequently Asked Questions
Do I need to pay for MySQL?
No. MySQL Community Server is completely free to download and use for this course and for most real projects.
What if I forget my root password?
MySQL provides a documented password-reset procedure for each operating system, but it is much simpler to just store the password securely from the start.
Can I use XAMPP instead of installing MySQL directly?
Yes. XAMPP bundles MySQL or MariaDB, and both work fine for following along with this course.
What port does MySQL use by default?
MySQL listens on port 3306 by default, which is what the command-line client and MySQL Workbench will connect to.
How do I know my installation worked?
If running `mysql -u root -p` and entering your password brings up the mysql> prompt, your installation is working correctly.
Key Takeaways
- MySQL Community Server is free and should be downloaded from the official dev.mysql.com site.
- Windows uses the MySQL Installer, while macOS and Linux offer package-based or DMG installs.
- You must set a root password during installation, and you should store it securely.
- Running `mysql -u root -p` from a terminal is the standard way to verify your installation.
- XAMPP is a convenient alternative that bundles MySQL/MariaDB for quick local development.
Summary
With MySQL Community Server installed and a root password set, you now have a working MySQL server on your own machine, ready to accept SQL commands.
In this lesson, you downloaded and installed MySQL, set a root password, and verified everything using the command-line client. Next, you will install MySQL Workbench, a graphical tool that makes working with MySQL much more visual and convenient.
- You have MySQL Community Server installed on your machine.
- You set and can recall your root password.
- You verified the installation with the mysql command-line client.
- You are ready to install MySQL Workbench.