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
- Log in to your server with SSH. SSH is a safe way to type commands on a remote computer.
- Update the package list:
sudo apt update - 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:
Replace VERSION with the number shown on the page.wget https://dev.mysql.com/get/mysql-apt-config_VERSION_all.deb - Install it:
A blue menu opens.sudo dpkg -i mysql-apt-config_VERSION_all.deb - Pick OK to accept the default MySQL 8 choice. Press Enter.
- Refresh the list again:
sudo apt update - Install the server:
You will be asked to set a root password. This is the database admin password, not the server login. Choose a strong one.sudo apt install mysql-server - Check the version:
mysql --version - Check that it runs:
Look for the word "active".sudo systemctl status mysql
Secure it
- Run the safety script:
It asks a few questions.sudo mysql_secure_installation - Say yes to removing anonymous users and test databases.
- 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.