Monday, November 25, 2024
Google search engine
HomeData Modelling & AIHow To Install MySQL 8.0 on Ubuntu 18.04 / 16.04

How To Install MySQL 8.0 on Ubuntu 18.04 / 16.04

In this guide, we will cover how to install MySQL 8.0 on Ubuntu 18.04 and 16.04 LTS Server. If you have an old version of MySQL Server (e.g 5.7), you may need to do in-place upgrade or dump all data, upgrade packages and re-import all database data.

Before you can download MySQL v8.0 to your Ubuntu 18.04 or 16.04 Server, you need to add official MySQL Dev apt repository. Run below command to download repository configuration file:

sudo apt update
sudo apt-get install wget
wget https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb

Then install the package on your Ubuntu system:

$ sudo dpkg -i mysql-apt-config_0.8.22-1_all.deb
(Reading database ... 60467 files and directories currently installed.)
Preparing to unpack mysql-apt-config_0.8.22-1_all.deb ...
Unpacking mysql-apt-config (0.8.22-1) over (0.8.17-1) ...
Setting up mysql-apt-config (0.8.22-1) ...
Warning: apt-key should not be used in scripts (called from postinst maintainerscript of the package mysql-apt-config)
OK

Choose version when prompted.

mysql install 8.0 ubuntu 18.04

Select <OK>  and press <Enter> key to confirm version installation.

Once the repo has been added, update apt index and install mysql-server:

sudo apt update
sudo apt install mysql-server

All dependencies are installed automatically:

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-client-plugins 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-client-plugins mysql-community-server
  mysql-community-server-core mysql-server
0 upgraded, 13 newly installed, 0 to remove and 38 not upgraded.
Need to get 41.1 MB of archives.
After this operation, 286 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Accept license agreement in the next screens to begin installation.

mysql install 8.0 ubuntu 18.04 05

Set root password for your MySQL database server.

mysql install 8.0 ubuntu 18.04 06

Confirm your root user password.

mysql install 8.0 ubuntu 18.04 07

Agree to retain compatibility.

mysql install 8.0 ubuntu 18.04 08

Select the default authentication plugin.

mysql install 8.0 ubuntu 18.04 09

When asked for root password, provide the password and confirm it to set.

Confirm installed version of MySQL server:

$ apt policy mysql-server
mysql-server:
  Installed: 8.0.28-1ubuntu18.04
  Candidate: 8.0.28-1ubuntu18.04
  Version table:
 *** 8.0.28-1ubuntu18.04 500
        500 http://repo.mysql.com/apt/ubuntu bionic/mysql-8.0 amd64 Packages
        100 /var/lib/dpkg/status
     5.7.37-0ubuntu0.18.04.1 500
        500 http://mirrors.digitalocean.com/ubuntu bionic-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages
     5.7.21-1ubuntu1 500
        500 http://mirrors.digitalocean.com/ubuntu bionic/main amd64 Packages

You can start the application if stopped using:

sudo systemctl enable --now mysql

Check status using:

$ systemctl status mysql
 mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2022-03-21 21:08:28 UTC; 39s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 4168 (mysqld)
   Status: "Server is operational"
    Tasks: 38 (limit: 2361)
   CGroup: /system.slice/mysql.service
           └─4168 /usr/sbin/mysqld
 Mar 21 11:15:29 ubuntu-01 systemd[1]: Starting MySQL Community Server…
 Mar 21 11:15:30 ubuntu-01 systemd[1]: Started MySQL Community Server.

Test MySQL 8.0 Database Functionality

You can test if the database server is working fine by creating a test database:

$ sudo mysql -u root -p
Enter password: <INPUT-PASSWORD-SET-EARLIER>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.19 MySQL Community Server - GPL
Copyright (c) 2000, 2020, 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> 

mysql> CREATE DATABASE test_db;
Query OK, 1 row affected (0.01 sec)

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test_db            |
+--------------------+
5 rows in set (0.01 sec)

mysql> DROP DATABASE test_db;
Query OK, 0 rows affected (0.01 sec)

mysql> EXIT
Bye

Install Desktop Database Management Tool

If working with MySQL command line is not your thing, then consider installing a Database Tool to help you. Check out our guide below:

Database books to read:

You can also see below related Articles:

RELATED ARTICLES

Most Popular

Recent Comments