Guides 11792 Published by

The guide walks you through adding Oracle’s MySQL 8.0 repository to Ubuntu, downloading the configuration package, installing it with dpkg, and then running an apt update so that the newest binaries become available. Once mysql‑server is installed it asks for a root password and immediately runs a secure installation script that removes anonymous accounts, blocks remote root logins, deletes test databases, and reloads privilege tables. You can confirm the server’s health by checking its status with systemctl, connecting to the MySQL shell, and running a simple SELECT version() query; this gives you an instant sanity check. Finally, the article reminds you to keep your packages up‑to‑date, back up regularly, and points out common troubleshooting steps such as inspecting journal logs if the service fails to start.



How to Install MySQL 8.0 Community Server on Ubuntu 22.04/20.04

If you’re looking for a fresh, up‑to‑date database that plays well with the latest Linux kernel, installing MySQL 8.0 on Ubuntu is quick and painless. By the end of this guide you’ll have a running server ready to accept connections from your applications.

1. Get the repo set up first

MySQL doesn’t ship in Ubuntu’s default apt sources for version 8.0, so you need to point apt at Oracle’s own repository. Skip this step if you’re ok with an older 5.7 package; otherwise, run:

sudo wget https://dev.mysql.com/get/mysql-apt-config_0.8.29-1_all.deb

This command downloads the official configuration package. You’ll be prompted to choose a MySQL version and server type—pick “MySQL Server & Cluster (Current Version)” and hit Enter twice.

> Why this matters: The config file tells apt exactly where to pull the 8.0 binaries from, avoiding any accidental upgrade of an older package that might break your apps.

2. Install the repo package
sudo dpkg -i mysql-apt-config_0.8.29-1_all.deb

During installation it will ask you whether to keep the current configuration or replace it; choose Keep unless you’re sure the existing file is stale.

If dpkg complains about missing dependencies, fix them:

sudo apt-get install -f

Now run a clean update so your package list reflects MySQL’s new sources:

sudo apt-get update

> Real‑world tip: I once hit an “Unable to locate package” error after adding the repo because apt was still caching the old list. A quick update solved it.

3. Install MySQL 8.0
sudo apt-get install mysql-server

The installer will pull in the server, client libraries, and a few utilities. You’ll be asked to set a root password—pick something that won’t make your kids cry.

During installation you might see a prompt about mysqld_safe. Just let it default; no need to tweak anything unless you’re building a complex cluster.

4. Harden the installation

MySQL ships with a handy script that removes anonymous users, disallows remote root logins, and drops test databases. Run it:

sudo mysql_secure_installation

Follow the prompts: confirm the root password you set earlier, choose to remove anonymous accounts, disable remote root access, delete the test database, and reload privilege tables.

> Why bother? Even if you’re only running a local dev server, those defaults are a common entry point for attackers or accidental data leaks.

5. Verify everything works
sudo systemctl status mysql.service

You should see an active (running) status. To double‑check connectivity:

mysql -u root -p

Enter your password, and you’ll land in the MySQL shell. Try a quick query:

SELECT version();

It should return something like 8.0.34 MySQL Community Server. Exit with \q.

If the service won’t start, check logs:

journalctl -u mysql.service --since "10 minutes ago"

Common issues include missing mysqld binary (rare) or port conflicts if another MySQL instance is running.

You now have a clean, secure MySQL 8.0 Community Server on Ubuntu 22.04 or 20.04. Time to start building your database‑backed app—just remember to back up regularly and keep your packages updated.