How to Install MySQL on Ubuntu 18.04

Install MySQL on Ubuntu 18.04

In this tutorial we will show you how to install MySQL on Ubuntu 18.04. We will also install and configure its prerequisites. MySQL is one of the most frequently used database management systems one of website/server applications. It allows users to store their databases and handle them using SQL commands on various platforms.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 18.04 LTS minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install MySQL on Ubuntu 18.04

Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:

apt-get update -y
apt-get upgrade -y

Step 2. Install MySQL on Ubuntu 18.04.

First, downloading the repository package using the wget tool from the command line:


Next, install the APT by dpkg:

sudo dpkg -i mysql-apt-config_0.8.9-1_all.deb

Then, Install the MySQL Server 8:

sudo apt-get update
sudo apt-get install mysql-server

Start the MySQL service and make it auto-start on system boot:

systemctl start mysql
systemctl enable mysql

Verify installation of MySQL:

mysql --version

Step 3. Secure MySQL.

Once the MySQL or MariaDB server has started, the service will then need to be secured. The mysql_secure_installation script will assist with this process by presenting several questions. It is recommended to accept the default action for all questions which is yes.


You will be given the choice to change the MySQL root password, remove anonymous user accounts, disable root logins outside of localhost, and remove test databases:

  • Set root password? [Y/n] Y
  • Remove anonymous users? [Y/n] Y
  • Disallow root login remotely? [Y/n] Y
  • Remove test database and access to it? [Y/n] Y
  • Reload privilege tables now? [Y/n] Y

To access the MySQL instance, run the following command on the terminal.

mysql -u root -p

Congratulation’s! You have successfully install and configured MySQL on your Ubuntu 18.04 Bionic Beaver. Thanks for using this tutorial installing MySQL data bases on Ubuntu 18.04 LTS (Bionic Beaver) system.