In this post:

  • Install default MySQL version (ritht now 5.7.21)
  • Install mysql 8 Ubuntu 16.04
  • Verify installation of MySQL
  • Secure MySQL 8
  • Errors and problems
  • Connect to MySQL 8

Install curent Ubuntu mysql

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

Install mysql 8 Ubuntu 16.04

There are several ways of MySQL installation on Ubuntu. One is to use the versions included in the APT package repository by default (which are 5.6 and 5.7), or you can install the latest version (currently 8) by manually adding MySQL's repository first. The first one is in the previous section, Here we are going to do the second one:

  • Update your system:
sudo apt-get update
sudo apt-get upgrade
  • Installing MySQL 8
  • Download MySQL APT Repository from: MySQL APT Repository (Click Download on the bottom right, then copy the link on the next page ( from No thanks, just start my download)). Sample code:
wget https://dev.mysql.com/get/mysql-apt-config_0.8.9-1_all.deb
  • Install the APT by dpkg

At this step you need to select what to be installed and press OK.

sudo dpkg -i mysql-apt-config_0.8.9-1_all.deb
  • Install the MySQL Server 8
sudo apt-get update
sudo apt-get install mysql-server
  • During installation you will be asked for root password. Select a good one and continue installation

Verify installation of MySQL

Installation can be verified by:

mysql --version

or by:

systemctl status mysql.service

result:

mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en
   Active: active (running) s..

Secure MySQL 8

Security script is used to optimise and secure your database. You can do it by and follow the insructions:

sudo mysql_secure_installation

Errors and problems

Normally after the installation the service should start by default. You can verify this by checking the MySQL status:

systemctl status mysql.service

In case of not working or stopped service you can check the MySQL logs by:

sudo tail -n 200 /var/log/mysql/error.log

Sometimes the problems could be due to wrong folder permissions like:

Folder /var/lib/mysql should be with mode 660

If this is a fresh installation you can completely uninstall the MySQL by:

sudo apt-get remove --purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean

and the reinstall the MySQL 8.

Some people report a problem connecting to MySQL Workbench which can be analyzed by this command (start MySQL workbench with this command):

MySQLWorkbench.exe -log-level=debug3

Depending on the error you can have different fixes. A common error after upgrade to MySQL is:

Authentication plugin 'caching_sha2_password' cannot be loaded:

This is because the new security policies of MySQL 8. This is explained in this article:

MySQL set or reset user password

Connect to MySQL 8

In order to connect use this script and enter your root password when asked:

mysql -u root -p

Create new Database and User

Database is created by:

create database mydb;
grant all on mydb.* to 'myuser' identified by 'password';

User creation:

create database mydb;
create user 'myuser'@'localhost' identified by 'password';
grant all on mydb.* to 'myuser';

Exit:

exit;