Migrate to RunxBuild and earn up to $50 in hosting credit on your first deposit.

Calculate your savings
unxBuild

Install MySQL on Ubuntu: apt, mysql_secure_installation, and 8.0 Setup

Sean

Platform Writer

Jul 05, 2026
5 min read

Install MySQL on Ubuntu via sudo apt install mysql-server. The Ubuntu docs walk through the setup. Run mysql_secure_installation post-install to set root password, remove anonymous users, and disable remote root login. The team that uses the official mysql-server package (Ubuntu’s curated) has stability; the team that uses MySQL’s apt repo has the latest version.

Install MySQL on Ubuntu: apt, mysql_secure_installation, and 8.0 Setup

Table of contents

Install via apt

sudo apt update
sudo apt install mysql-server

This installs MySQL 8.0 on Ubuntu 22.04, 8.0 or 8.4 on 24.04.

Start the service

sudo systemctl enable --now mysql
sudo systemctl status mysql

The team that enables the service has MySQL start at boot.

mysql_secure_installation

sudo mysql_secure_installation

This walks through:

  1. Set root password.
  2. Remove anonymous users.
  3. Disallow root login remotely.
  4. Remove test database.
  5. Reload privilege tables.

The team that runs this has hardened MySQL. The team that skips has anonymous users and weak root.

Create a database and user

sudo mysql

CREATE DATABASE myapp;
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON myapp.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

The team that creates app-specific users has least-privilege. The team that uses root for everything has a security incident.

Allow remote connections

Edit /etc/mysql/mysql.conf.d/mysqld.cnf:

bind-address = 0.0.0.0   # or specific IP

Restart:

sudo systemctl restart mysql

Then CREATE USER 'appuser'@'%' IDENTIFIED BY 'pwd'; for remote. The team that opens remote access also opens 3306 in the firewall.

Configure for production

  1. Set innodb_buffer_pool_size to ~50% of RAM.
  2. Set max_connections based on workload (default 151).
  3. Set slow_query_log = 1 for performance debugging.
  4. Set log_error to a persistent location.
  5. Backup: mysqldump + cron, or Percona XtraBackup for hot backups.

Test the install

sudo mysqladmin -u root -p version

Shows MySQL version. The team that verifies has working install.

FAQ

What’s the default MySQL user after install?

root, authenticated via auth_socket plugin (Ubuntu’s default - uses OS user, not password). The team that changes this for production has password auth.

How do I reset the root password?

sudo systemctl stop mysql
sudo mysqld --skip-grant-tables &
mysql -u root
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpwd';

Then restart. The team that has the recovery path can reset.

Can I install multiple MySQL versions?

Yes via Ubuntu’s mysql-X.Y packages or Docker. The team that tests across versions has multi-version setup.

Where are MySQL config files?

/etc/mysql/mysql.conf.d/mysqld.cnf (Ubuntu), /etc/my.cnf (RHEL). The team that edits these has full config control.

How do I enable slow query log?

SET GLOBAL slow_query_log = 'ON'; or in my.cnf: slow_query_log = 1, long_query_time = 2. The team that monitors slow queries has performance visibility.

If you are sizing the infrastructure for the kind of project this post covers, the RunxBuild hosting calculator is the right place to model the line items. The compute, the memory, the storage, the bandwidth, the database - each one is a separate number, and the team’s mental model for the platform is the sum of those numbers. The RunxBuild dashboard is where the team sees the actual usage in one place.

Useful related references:

#mysql#ubuntu#install#dev-infra