Select Page

Installing MySQL on Ubuntu 18.04LTS

Installing MySQL on Ubuntu 18.04LTS


The LAMP stack (Linux, Apache, MySQL or MariaDB, PHP) is the most popular web development stack in use at the moment.

Whilst many people have migrated from MySQL to MariaDB since Oracles purchase of Sun and thereby MySQL back in 2009, many are still faithful to the Dolphin Logo’d database.

I have no issue with using MySQL or MariaDB, and I’m guessing if you’re here then you’re interested in MySQL so read on.


Being prepared is always a good start so before we begin let’s ensure our Ubuntu is up to date.

> sudo apt update && sudo apt upgrade

Installing The Software

Before we can get things set up we need to install the software.  This is easy and done by the following:

> sudo apt install mysql-server mysql-client

If you are not intending to run the applications that connect to the databaseL on the same server you can ommit the mysql-client.

On hitting [ENTER] you will be shown all the associated packages (dependencies) that will be installed.  It might seem like a lot but don’t worry – we’ll be needing them so confirm installation by typing [Y] and pressing the [ENTER] key.

Depending on your server and internet connection speed, this can take a while so sit back and relax.

When complete you’ll be returned to the command prompt.

Setting up MySQL

MySQL is installed and ready to go but before we do anything else we really need to tighten up security as a blank password is no good to anyone except those that inhabit the darker corners of the net.

> sudo mysql_secure_installation


Type [Y] and hit the [ENTER] key.


We need to select the password policy before we continue.  Select your desired level (please not level 0) and press the [ENTER] key.

Now typer the new password for root access (the super dooper can do anything admin user), and press the [ENTER] key.

Your password will be given a score.  If it’s under 50 then try again – you can proceed but you want your database server to be secure don’t you?


Unless you really have a good need for a default anonymous user, remove it by typing [Y] and then hitting [ENTER].  You can add users later.


Allowing root access remotely is not the best idea, and it’s usually best to disallow it.  Now let’s not get confused here.  This doesn’t mean you have to be at the server console to use root access.  You can log into the server remotely and the use the MySQL root user.  It simply means you can not connect directly do the database from a remote source using the root user.

So type [Y] and hit [ENTER].


MySQL also installs itself with a test database.  Again it’s best to remove this unless you really need it so type [Y] and hit [ENTER].


Finally you’ll be prompted to reload the privilege tables which is another good idea.  So type [Y] and hit [ENTER].

So that’s it – MySQL is now installed.

Leave a reply