How to Install MySQL 8.0 on Ubuntu 18.04

In this brief tutorial, we'll look at how you can install MySQL 8.0 on Ubuntu 18.04. MySQL is a free and opensource cross-platform database server that is used on many opensource projects and high availability systems such as LAMP and LEMP stacks, IoT to mention but a few. However, It has been overshadowed by MariaDB in terms of popularity, but still remains an important database server for dozens of open source projects.

New features in MySQL 8.0

  1. MySQL replication enhancements
  2. Improved security and account management
  3. JSON improvements
  4. Improved optimizer
  5. A new type of backup lock
  6. Support for common table expressions (both non-recursive and recursive).
  7. Atomic DDL statement support
  8. Support for regular expression using International Components for Unicode (ICU).

How to install MySQL 8.0 on Ubuntu 18.04

Using root privileges, Login to your Ubuntu 18.04 instance and follow the steps below

Step 1: Add MySQL APT repository

Download the repository using wget or curl command line tool

 wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.10-1_all.deb

Sample Output

--2018-06-22 11:39:09--  https://dev.mysql.com/get/mysql-apt-config_0.8.10-1_all                                                                                        .deb
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql-apt-config_0.8.10-1_all.deb [following]
--2018-06-22 11:39:10--  https://repo.mysql.com//mysql-apt-config_0.8.10-1_all.d                                                                                        eb
Resolving repo.mysql.com (repo.mysql.com)... 104.106.8.147
Connecting to repo.mysql.com (repo.mysql.com)|104.106.8.147|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 35970 (35K) [application/x-debian-package]
Saving to: ‘mysql-apt-config_0.8.10-1_all.deb’

mysql-apt-config_0. 100%[===================>]  35.13K  --.-KB/s    in 0.01s

2018-06-22 11:39:10 (3.10 MB/s) - ‘mysql-apt-config_0.8.10-1_all.deb’ saved [359                                                                                        70/35970]

Confirm that you have downloaded using the lscommand.

Step 2: Install The MySQL repository package

Next, using the dpkg package tool, install the MySQL repository package as shown below

 dpkg -i mysql-apt-config_0.8.10-1_all.deb

After running the above command, you get a display prompt giving you a selection of MySQL instances you can choose from. Scroll down and select the last option - "Ok"

Selecting previously unselected package mysql-apt-config.
(Reading database ... 51260 files and directories currently installed.)
Preparing to unpack mysql-apt-config_0.8.10-1_all.deb ...
Unpacking mysql-apt-config (0.8.10-1) ...
Setting up mysql-apt-config (0.8.10-1) ...

Step 3: Install MySQL server and client

Next, run the command below to install MySQL server instance and client which is used for remotely logging to MySQL server

sudo apt install mysql-server mysql-client

You'll be prompted to provide a MySQL root password to access the database

Next, you'll be required to choose the default authentication plugin. Select the first option and hit 'Enter'

install MySQL 8.0 on Ubuntu 18.04

To confirm that we have successfully installed MySQL server and MySQL client in our system, run

dpkg -l | grep "mysql"

Sample output
install MySQL 8.0 on Ubuntu 18.04

Step 4: Securing MySQL installation

By default, MySQL is insecure and therefore, we need to secure the database server. To do so, run

mysql_secure_installation

This will present you with a list of prompt questions. You'll first be required to enter the root password - The one you created during MySQL setup. Next, you'll be asked whether to opt for VALIDATE PASSWORD plugin or not. This enables you to test MySQL passwords and improve security.

install MySQL 8.0 on Ubuntu 18.04

Next, you'll be required to answer yes or no to the following questions:

  • Remove anonymous users? (Press y|Y for Yes, any other key for No)
  • Disallow root login remotely? (Press y|Y for Yes, any other key for No)
  • Remove test database and access to it? (Press y|Y for Yes, any other key for No)
  • Reload privilege tables now? (Press y|Y for Yes, any other key for No)

install MySQL 8.0 on Ubuntu 18.04

Step 5: Managing MySQL Server using Systemd

By default, MySQL service starts automatically upon installation. To check its status run

systemctl status mysql-server

install MySQL 8.0 on Ubuntu 18.04

To stop the service run

systemctl stop mysql

To start the service run

systemctl start mysql

To enable MySQL on boot up run

systemctl enable mysql

Output

Synchronizing state of mysql.service with SysV init with /lib/systemd/systemd-sysv-install...
Executing /lib/systemd/systemd-sysv-install enable mysql

Step 5: Logging to MySQL database as root

To login to your database engine run

mysql -u root -p

The -u flag specifies the root login. The -p flag prompts for the password.

Type your password and hit Enter to get into MySQL prompt as shown below.

Displaying information about MySQL database server

To display more information about your database server such as the server version and uptime, run

mysqladmin -u root -p version


Read also

Final Word

Congratulations! You have successfully installed and tested your MySQL 8.0 database server! If you wish to interact with the database with a GUI, install PHPMyAdmin utility which will allow you to intuitively administer your databases. That's all for now. We have outlined how you can install  MySQL 8.0 on Ubuntu 18.04. Keep it locked for more insightful posts :-)

Jamie Arthur 5:34 am

About Jamie Arthur

Hey, I'm James, a passionate Linux Systems administrator, and a tech enthusiast. I derive immense gratification in conducting research on Linux systems and keeping myself up to date with the latest in the technology world.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.