Skip to content
datahacks.dev
MySQL

Installing MySQL 8.4 on macOS Linux and Windows Step by Step

Install MySQL 8.4 LTS on macOS, Ubuntu and Windows: package sources, first start, the root account, secure setup and checks that the server works.

6 min read
Summarize in AI
Flat illustration of settings switches, a slider and a gear, with the MySQL logo.

Installing MySQL looks routine and has a few choices that matter later: which release line, which package source, where the data lives and how the root account starts out. This article installs MySQL 8.4 LTS on the three common desktop and server platforms, walks through the first start and secures the result. It sticks to supported installers from the project and Homebrew, and it ends with checks that the server is what you expect before an application connects.

Pick the release

MySQL has long term support releases and innovation releases. Version 8.4 is the LTS line, supported for years with bug and security fixes and no feature changes, and it is the right default for a database that will run for a long time. Innovation releases such as 9.x ship new features quickly and are supported only until the next one. Version 8.0 is at or near end of life according to Oracle's lifetime policy, so do not start new work on it. The reasoning is in which MySQL version to choose for a new project. MariaDB is a separate fork with its own packages and differences, not covered here.

macOS with Homebrew

Shell
brew install [email protected]
brew services start [email protected]

Homebrew installs a versioned formula and puts binaries under its prefix without linking them to your path, so add them: echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zshrc on Apple silicon (the prefix is /usr/local on Intel Macs). The data directory is /opt/homebrew/var/mysql and the configuration file /opt/homebrew/etc/my.cnf. The root account starts with no password, reachable only from localhost. The installer from the MySQL download page is an alternative that registers a system service and prompts for a root password.

Ubuntu and Debian

The distribution repositories often carry an older version, so add the MySQL APT repository. Download the mysql-apt-config package from the MySQL downloads page, install it with sudo dpkg -i, choose the 8.4 LTS server in its menu, and then:

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

The installer asks for a root password, or sets up authentication through the socket so that sudo mysql works without one. Data lives in /var/lib/mysql, configuration in /etc/mysql/, and logs in /var/log/mysql/ or the journal. Red Hat family systems use the MySQL Yum repository with dnf install mysql-community-server; the first start writes a temporary root password to the error log (sudo grep 'temporary password' /var/log/mysqld.log) that you must change at first login.

Windows

Download the MySQL Installer (MSI) from the MySQL website, choose the Server only or Developer setup, pick 8.4, and set the root password and the service name when the wizard asks. The server runs as a Windows service, MySQL84 by default, and its files sit under C:\\ProgramData\\MySQL\\MySQL Server 8.4\\ with my.ini as the configuration file. Use the "MySQL 8.4 Command Line Client" shortcut or add the bin directory to the path. Keep the data directory off folders that a backup or antivirus tool scans aggressively, since it hurts performance.

First start and the root account

On first start the server initializes the data directory. Depending on the package, root has an empty password, a generated temporary one or socket authentication. Replace it at once:

SQL
ALTER USER 'root'@'localhost' IDENTIFIED BY 'a-long-generated-password';

Version 8.4 defaults to the caching_sha2_password plugin, and the older mysql_native_password is disabled by default, which matters for old clients and is covered in fixing authentication plugin caching_sha2_password errors. Then run the hardening script:

Shell
sudo mysql_secure_installation

It sets the password policy, removes anonymous accounts and the test database, and disallows remote root login. The details of what it changes are in removing anonymous users and test databases.

Check what you installed

Connect and ask the server:

SQL
SELECT VERSION();
SHOW VARIABLES LIKE 'character_set_server';
SHOW VARIABLES LIKE 'datadir';
SHOW VARIABLES LIKE 'port';

You should see a version starting with 8.4, utf8mb4 as the server character set (the right default; see why utf8mb4 is the only charset you should use), the data directory you expect and port 3306. Check that the server listens only where intended: SHOW VARIABLES LIKE 'bind_address' is 127.0.0.1 or * depending on the package, and opening it to the network without a firewall and TLS is a decision to make later with care. Look at the error log once to confirm a clean start with no warnings about deprecated settings.

Keeping the install updatable

Write down how the server was installed and how it will be updated. Package-managed installs receive minor updates through the package manager, and a monthly check of the release notes for security fixes is a good habit. Homebrew upgrades replace the formula in place, and a major version change needs a deliberate step. Pin the version in configuration management so that a new machine matches the old one. Keep the configuration file in version control, and note any non-default setting with the reason, since the file is the part of the install that people forget to document.

Common first problems

If the service does not start, read the error log, whose location is SHOW VARIABLES LIKE 'log_error' or the journal. Typical causes are a port already in use by another MySQL or MariaDB, permissions on the data directory, or a leftover data directory from another version that the new server refuses to open. ERROR 1045 Access denied for root is covered in fixing access denied for user root at localhost, and a missing socket in fixing can not connect to local MySQL server through socket. On macOS, an older Homebrew MySQL or the Oracle installer may already occupy the port; stop it first.

When Docker is the easier install

For development, a container keeps the server, its version and its files apart from your system and removes the platform differences above. One command starts a throwaway or persistent server, as shown in running MySQL in Docker with a data volume. Use native packages for a server that stays up, a machine where Docker is not available or when you want the service manager integration. For production on a managed cloud, none of this applies, since the provider installs and patches the server.

What to do next

Install 8.4 on the platform you use, change the root password, run the secure script and create an application user. Save the commands you used in your notes so the next machine is a copy. The manual documents every platform in installing MySQL, and the Homebrew formula is described at formulae.brew.sh. The hub is getting a MySQL server running and usable.

Share

Keep reading

Get new articles by email

We send one email when a new article is published. No spam.

Unsubscribe in one click. No spam, ever.