In this tutorial, we learn how to install MySQL 8.0 on Ubuntu 16.04 (Xenial Xerus) from MySQL apt repository.
MySQL 8.0 is the long-awaited release of MySQL that brings a lot of new features and enhancements.
This tutorial assumes that we have a fresh install of Ubuntu Server 16.04 (Xenial Xerus). You can also follow this tutorial on any flavor of Ubuntu 16.04, like Kubuntu or Xubuntu.
Please take extra caution when you’re following this tutorial on production server that already serving production workload.
Install MySQL 8.0
Let’s start our process of installing MySQL 8.0 on ubuntu 16.04.
First of all we will update our system to latest update. Even though we have fresh install of Ubuntu, there might be update that is not applied to our system yet. We can use command below to update our system.
sudo apt-get update sudo apt-get upgrade
Add MySQL apt repository
MySQL developers provides a .deb package that we will create new apt configuration for our systems.
Go to Download MySQL apt repository and click Download.
Find the link that says, “No thanks, just start my download,” right-click the link and copy link address. We use the link that we copied on the next step.
Now let’s download deb package that we just copy the link from MySQL download page.
wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.10-1_all.deb
-c option above means wget will continue the previous download file if it’s disconnected instead of creating new file.
After downloading the file, we need to check the md5 checksum of the file. We use the MD5 checksum file to ensure the integrity of the file that we download.
md5sum mysql-apt-config_0.8.10-1_all.deb 5b36dd754e7752162f890206fae50931 mysql-apt-config_0.8.10-1_all.deb
Make sure the output above match with the one listed on MySQL apt download page.
Install mysql-apt-config package using
sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb
We enable MySQL tools and Connectors repository.
And we disable MySQL Preview Packages since we don’t need it
Choose OK and OK button to continue.
After MySQL repository configured we can remove the deb file since we already install the package and don’t need the .deb anymore.
rm -f mysql-apt-config_0.8.10-1_all.deb
Update apt metadata since we’re adding new repository
sudo apt-get update
Install MySQL Server 8.0
We can install MySQL Server 8.0 by installing
mysql-server package. Since we already add MySQL apt repository this will be preferred instead of mysql-server package from Ubuntu repository.
sudo apt-get install mysql-server
apt will list packages that will be installed. Press enter to continue the installation
Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libaio1 libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-server mysql-community-server-core The following NEW packages will be installed: libaio1 libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-server mysql-community-server-core mysql-server 0 upgraded, 12 newly installed, 0 to remove and 32 not upgraded. Need to get 49.2 MB of archives. After this operation, 403 MB of additional disk space will be used. Do you want to continue? [Y/n]
Enter the MySQL root password. Please note MySQL root user and system root user is two different user and not related.
Re-enter root password
MySQL installer will do the rest of the installation process.
Check MySQL 8.0 Service on Ubuntu 16.04
To check mysql service, we can use service command
sudo service mysql status
It will give output similar to below if MySQL Server is running
● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2018-07-08 07:30:00 UTC; 13s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Main PID: 3506 (mysqld) Status: "SERVER_OPERATING" CGroup: /system.slice/mysql.service └─3506 /usr/sbin/mysqld Jul 08 07:29:59 ubuntu-xenial systemd: Starting MySQL Community Server... Jul 08 07:30:00 ubuntu-xenial systemd: Started MySQL Community Server.
We can also use
systemctl command to check service since we’re running Ubuntu 16.04
sudo systemctl status mysql.service
Check MySQL Server 8.0 Listen Port
We can check which port MySQL listen using
To check with netstat we can use command below
$ sudo netstat -napt | grep mysql tcp6 0 0 :::3306 :::* LISTEN 3506/mysqld tcp6 0 0 :::33060 :::* LISTEN 3506/mysqld
To check with ss we can use command below
$ sudo ss -ltn -p | grep mysql LISTEN 0 128 :::3306 :::* users:(("mysqld",pid=3506,fd=20)) LISTEN 0 70 :::33060 :::* users:(("mysqld",pid=3506,fd=23))
Both output above provide similar output that MySQL listen on both port 3306 and 33060.
Port 3306 is MySQL port, while port 33060 is MySQL extended protocol. It will listen when X plugin enabled and in MySQL 8.0 this plugin enabled by default.
Securing MySQL 8.0 Installation
Before we start using MySQL installation let’s secure mysql installation. MySQL shipped with utility named
Input root password that we already set on installation.
Securing the MySQL server deployment. Enter password for user root:
MySQL have plugin to validate password that will check password strength. Press
VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: y
Choose 2 for level of password validation policy and press choose
N on changing root password since want to keep current root password.
There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 Using existing password for root. Estimated strength of the password: 100 Change the password for root? ((Press y|Y for Yes, any other key for No): N ... skipping.
y to remove anonymous user
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success.
y to disallow root user to login remotely.
Usually, root should only be allowed to connect from 'localhost.' This practice ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y Success.
y to remove default test database
By default, MySQL comes with a database named 'test' that anyone can access. This database is also intended only for testing and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - Dropping test database... Success. - Removing privileges on test database... Success.
y to reload privilge table.
Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done!
Now our MySQL installation secured.
Testing access to MySQL 8.0
Now let’s test access to MySQL using mysql client.
mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 8.0.11 MySQL Community Server - GPL Copyright (c) 2000, 2018, 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. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
To quit from mysql client you can type
We can also test access to MySQL database using
Let’s give ping command to mysql
$ mysqladmin -u root -p ping Enter password: mysqld is alive
Output above shows that mysql is running
Now let’s check MySQL version
$ mysqladmin -u root -p version Enter password: mysqladmin Ver 8.0.11 for Linux on x86_64 (MySQL Community Server - GPL) Copyright (c) 2000, 2018, 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 8.0.11 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/run/mysqld/mysqld.sock Uptime: 36 min 30 sec Threads: 2 Questions: 10 Slow queries: 0 Opens: 110 Flush tables: 2 Open tables: 86 Queries per second avg: 0.004
Several references that you can read to learn more about MySQL 8.0:
In this tutorial we learned how to install MySQL 8.0 on Ubuntu 16.04 from MySQL official apt repository.
We also learn securing our mysql installation by running
We test accessing MySQL using
mysql client and
If you find this tutorial useful, please leave a comment below.
Correction, suggestions, and requests additional details to be added to this tutorial are welcome. Until next time!