MENU
Setting Up MySQL Server
Getting the MySQL engine running requires different steps depending on the host operating system.Since MySQL 8.4, releases follow two parallel tracks. Innovation releases (the 9.x line: 9.0, 9.1, 9.2, and so on) ship quickly and introduce new features first, but each one carries only a short support window. LTS (Long-Term Support) releases trade new features for years of stability - MySQL 8.4 was the first LTS release (supported into 2032), and MySQL 9.7 has since succeeded it as the newest LTS release. For learning and production alike, download an LTS release; 8.4 remains a solid, widely-deployed choice. Expect to see version numbers like 8.4 or 9.x on the download page depending on which track is selected.
Windows
Download the MySQL Community Edition installer from dev.mysql.com, selecting the 8.4 LTS release.Choose Developer Default as the setup type, which installs MySQL Workbench alongside the server. Follow the installation wizard through to completion.
Configure the remaining settings, including the root password. When prompted, uncheck "Bootstrap MySQL Router for use with InnoDB Cluster".
Once installation finishes, search for and launch MySQL Workbench, then log into the localhost instance by entering the root password.
Linux (Ubuntu)
Since Linux is free to use, running a MySQL server on it (for example, on an AWS EC2 instance) can help lower operating costs. Many Linux distributions include a version of the MySQL server, client tools, and development components in their native software repositories, installable through the platform's standard package management system.The script below installs MySQL Server 8.4 (the current LTS release) manually on Ubuntu 22.04 LTS, sets the root password, enables the service at boot, inspects its status and logs, and finally installs MySQL Workbench (a GNOME application that is only formally supported on the GNOME desktop, though it typically runs fine on other desktop environments too). Note that mysql_native_password is disabled by default as of MySQL 8.4; caching_sha2_password is now the default authentication plugin.
Mac
Installing MySQL on macOS follows the same process as on Windows. Download the installer from dev.mysql.com and choose macOS as the operating system.XAMPP
As an alternative, XAMPP includes MySQL out of the box, though it does not include MySQL Workbench.XAMPP is a free, open-source, cross-platform software package that provides an easy way to install and configure a web server stack on a local computer. The name "XAMPP" stands for the components it includes:
- X: Cross-platform
- A: Apache web server
- M: MySQL database server
- P: PHP scripting language
- P: Perl scripting language
XAMPP targets developers who need to test web applications locally before deploying them to a production server. It is easy to install and provides a simple graphical interface for starting and stopping the Apache web server and MySQL database server with just a few clicks.
XAMPP is available for Windows, Linux, and macOS, and can be downloaded from the Apache Friends website. While useful for local development and testing, it is not recommended for a production environment due to security concerns.
To use a separately installed MySQL version with XAMPP, copy the contents of the "bin" folder from that MySQL installation into the "bin" folder of the XAMPP installation directory, overwriting any existing files.
ch01-ubuntu-setup.sh:
#!/bin/bash
# Installing and managing MySQL Server 8.4 (LTS) on Ubuntu 22.04 LTS
# Patch the system
sudo apt update
sudo apt list --upgradable
sudo apt upgrade
# Search for MySQL server packages
apt-cache search mysql-server
apt info -a mysql-server-8.4
# Install the MySQL server package
sudo apt install mysql-server-8.4
# Set the root password (inside the mysql client)
sudo mysql
# ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'my_password';
# -- caching_sha2_password is the default plugin; mysql_native_password is disabled by default as of MySQL 8.4
# exit
# Configure a few more security-related settings
sudo mysql_secure_installation
# Enable MySQL Server at boot time; start, stop, and inspect the service
sudo systemctl is-enabled mysql.service
sudo systemctl enable mysql.service
sudo systemctl status mysql.service
sudo systemctl start mysql.service
sudo systemctl stop mysql.service
sudo systemctl restart mysql.service
sudo systemctl edit mysql.service
# View the MySQL service log
sudo journalctl -u mysql.service -xe
# Log in and test (inside the mysql client)
mysql -u root -p
# CREATE DATABASE mydemodb;
# Install MySQL Workbench
sudo apt update && sudo apt upgrade
sudo apt install mysql-workbench
sudo apt install ./mysql-apt-config_0.8.22-1_all.deb
sudo apt update
sudo apt install mysql-workbench-community
mysql-workbench