Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to install the latest MySQL on Ubuntu 18.04

This guide shows you how to install MySQL 8 on an Ubuntu 18.04 server and secure it.

Databases2 min read12 steps

This guide needs root access, so it fits VPS and dedicated server customers.

Tip: Ubuntu 18.04 is old software. Newer Ubuntu versions use almost the same steps, so you can follow this guide there too.

What is MySQL?

MySQL is a popular system for storing data. A database made with it is like a filing cabinet for your site or app. Ubuntu 18.04 ships with MySQL 5.7 in its default list. To get the newest version, add the official MySQL list, called a repository. A repository is an online store of software.

Steps

  1. Log in to your server with SSH. SSH is a safe way to type commands on a remote computer.
  2. Update the package list:
    sudo apt update
  3. Download the MySQL repository setup package from the official MySQL download page. Look for the "APT repository" file ending in .deb. Use the file name you see there:
    wget https://dev.mysql.com/get/mysql-apt-config_VERSION_all.deb
    Replace VERSION with the number shown on the page.
  4. Install it:
    sudo dpkg -i mysql-apt-config_VERSION_all.deb
    A blue menu opens.
  5. Pick OK to accept the default MySQL 8 choice. Press Enter.
  6. Refresh the list again:
    sudo apt update
  7. Install the server:
    sudo apt install mysql-server
    You will be asked to set a root password. This is the database admin password, not the server login. Choose a strong one.
  8. Check the version:
    mysql --version
  9. Check that it runs:
    sudo systemctl status mysql
    Look for the word "active".

Secure it

  1. Run the safety script:
    sudo mysql_secure_installation
    It asks a few questions.
  2. Say yes to removing anonymous users and test databases.
  3. Say yes to disallowing remote root login.

Warning: If your server already has a MySQL or MariaDB database, back it up before installing. An upgrade can change your data files.

Try it

sudo mysql -u root -p

This opens MySQL as the admin. Type SHOW DATABASES; to see the list. Type EXIT; to leave.

If something fails, open a support ticket.

Quick recap

  • Ubuntu 18.04 default list has an older MySQL.
  • Add the official MySQL repository to get version 8.
  • Install with apt install mysql-server.
  • Run mysql_secure_installation.
  • Back up any existing databases first.