/Installing the Latest MySQL on Ubuntu 16.04

Installing the Latest MySQL on Ubuntu 16.04

Introduction

Having the latest version of MySQL is very important. Fortunately, keeping MySQL up-to-date is not a hard task. In this tutorial, we will walk through the steps of installing the latest version of MySQL on Ubuntu 16.04.

Before starting, you will need an Ubuntu 16.04 server with a non-root and sudo-enabled.

Step 1 — Adding MySQL Software Repository

MySQL offers a tool to take care of configuring and install the MySQL software repositories – .deb tool. After the repositories are set up, you will have access to use the Ubuntu standard apt-get command to install the software. Download the .deb file with curl and then install it with the dpkg command.

Right after, you will need to load the MySQL download in your browser and start the download by clicking on the button in the right-lower corner. There will be a login page for an Oracle account, ignore the login and click on “No thanks”. The download will start automatically. Make sure to copy the Link Address.

When all of this is done, move to directory on the server and input:

$ cd /tmp

Download the file using curl and paste the link address you copied previously in the highlighted space:

$ curl -OL https://dev.mysql.com/get/mysql-apt-config_0.8.3-1_all.deb

We will pass two command line flags to curl. -O instructs curl to output to a file instead of standard output. The L flag makes curl follow HTTP redirects. This occurs because we have copied an address that redirects it to another location, before any downloads. The file is now downloaded in our directory.

List the files to double check:

$ ls

There should be this filename listed:

Output
mysql-apt-config_0.8.3-1_all.deb
...

Now it is ready for installation:

$ sudo dpkg -i mysql-apt-config*

dpkg is used for installation, removing and inspecting .deb software packages. The -i flag demonstrates that we would want to install from the specific file.

While installing, there will be a configuration screen that will offer which version of MySQL you would choose. There will be other options as well to install repositories for other MySQL-related tools.

The most up-to-date version of MySQL will have the defaults add the repository information. Use the down arrow towards the “Ok” menu option and click “ENTER”.

The package will have added the repository. Refresh your apt package cache to make the new software packages available:

$ sudo apt-get update

Afterwards, delete the file you have downloaded: 

$ rm mysql-apt-config*

The MySQL repositories are now added. We are now ready to install the MySQL server software. Run sudo dpkg-reconfigure mysql-apt-config if you ever need to update the configuration of these repositories. Select new options, and then sudo apt-get update to refresh your package cache.

Step 2 – Installing MySQL

After adding the repository and refreshing the package cache, we can now install the most up-to-date MySQL server package by using apt-get:

$ sudo apt-get install mysql-server

apt-get will analyze all possible mysql-server packages. After analyzing, it will determine which package is the most up-to-date and the better one.

The package dependencies will be calculated and request an approval for installation. Input y then ENTER. The installation will start and you will be asked for the root password when the installation is at the configuration phase.

For the password, double check that you have one that is secured and enter it twice to finish the process.

MySQL should be installed and working properly. We can double check by inputting:

$ systemctl status mysql

Output
mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2017-04-05 19:28:37 UTC; 3min 42s ago
Main PID: 8760 (mysqld)
CGroup: /system.slice/mysql.service
└─8760 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Active: active (running)” means MySQL is installed and running. Afterwards, we need to make the installation more secure.

 

Step 3 — Securing MySQL

You can execute a couple of security-related updates with the MySQL command. Start by inputting:

$ mysql_secure_installation

After this step, you will be asked for the root password that you previously set.

Afterwards, we will need to set up some steps. You will be asked about the validate password plugin which automatically enforce some password strength for your MySQL users. Having this security feature is an individual security needs. You can either type y and ENTER to turn it on, or click on ENTER to not turn it on. If you decide to have this option, you will be asked which level you want the restriction to be (0-2). Choose the level and click ENTER.

The next step will give you the option to change your root password. However, since it was recently created, this step can be skipped by clicking ENTER.

For the rest of the prompts (removing the anonymous MySQL user, disallowing remote root login, removing the test database, and reloading privilege tables) can all be answered by yes. These are good features, to answer yes, input y and hit ENTER.

Afterwards, the MySQL is now secure. To double check, you can run a client that connects to the server and returns information.

Step 4 – Testing MySQL

mysqladmin is a command line administrative client for MySQL. It will be used to connect to the server and output some version and status:

$ mysqladmin -u root -p version

The -u root portion tells mysqladmin to login as the MySQL root user.

The -p tells the client to ask for a password. Version is the command we want to run.

The output will let us know what version of the MySQL is running, the uptime and other information.

Output
mysqladmin  Ver 8.42 Distrib 5.7.17, for Linux on x86_64
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Server version      5.7.17
Protocol version    10
Connection      Localhost via UNIX socket
UNIX socket     /var/run/mysqld/mysqld.sock
Uptime:         58 min 28 sec

Threads: 1  Questions: 10  Slow queries: 0  Opens: 113  Flush tables: 1  Open tables: 10

You have now successfully installed the latest MySQL and secured it!

Be sure to check out our other tutorial if you are interested in learning more about MySQL and/or Ubuntu.

2017-08-25T22:09:43+00:00 August 25th, 2017|0 Comments

Leave A Comment