How to install MySQL 8.0 in Debian

MySQL

MySQL is a fast, efficient, secure, stable, easy-to-use, multi-platform, multi-threaded, multi-user, and well-documented relational database manager/server. Currently Oracle guides the development of MySQL, however the community version is available under the GPL license so it is still free software.

MySQL 8.0:

  • Add a new caching_sha2_password authentication plugin is available. Like the sha256_password plugin, caching_sha2_password implements SHA-256 password hashing, but uses caching to address latency issues at connect time.
  • Supports roles, which are named collections of privileges. Roles can be created and dropped. Roles can have privileges granted to and revoked from them. Roles can be granted to and revoked from user accounts.
  • Incorporates the concept of user account categories, with system and regular users distinguished according to whether they have the SYSTEM_USER privilege
  • Maintains information about password history, enabling restrictions on reuse of previous passwords also it is possible to configure user accounts such that too many consecutive login failures due to incorrect passwords cause temporary account locking.
  • Add the new authentication mechanism: caching_sha2_password that implements the SHA-256 encryption algorithm (like the sha256_password mechanism) but using a cache to solve latency problems during the connection process.
  • Incorporates several improvements to the InnoDB engine and the JSON data type.

You can check: What Is New in MySQL 8.0 for more information

Install

MySQL 8.0 is not available in the official Debian repositories, it has been replaced by MariaDB: a fork of MySQL, MariaDB share features with MySQL but has a different development model and community.

MySQL 8.0 can be downloaded from the MySQL download site, however it is recommended to download the repository definition to keep updated with improvements and bug fixes.

Download repo definition

Go to download section and select MySQL Community (GPL) Downloads, later MySQL APT Repository click on Download and we’ll get a page like this:

image

Mouse over the link: “… just start my download” and copy link address, and execute CURL o wget

$ curl -LO# https://dev.mysql.com/get/mysql-apt-config_0.8.17-1_all.deb

Install the repo

$ sudo sh -c 'apt install lsb-release gnupg wget && dpkg -i mysql-apt-config_0.8.17-1_all.deb'

MySQL repo config

configuración apt

Install server and client

$ sudo apt update && sudo apt install mysql-server

root password configuration

root password configuration

Authentication mechanism

Authentication mechanism

Select authentication mechanism

Select authentication mechanism

Manage the server process

In this part we will learn how to start, stop or restart the mysql service and we will use the systemd initialization system (systemd is a replacement for the SysV initialization system also a configuration and service management suite for the GNU/Linux operating system)

Check the status

Check if your DB server has started sucessfully by executing the following command

$ sudo systemctl status mysql
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2021-04-02 21:46:43 CEST; 2min 59s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 20071 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 20106 (mysqld)
   Status: "Server is operational"
    Tasks: 38 (limit: 2296)
   Memory: 337.1M
   CGroup: /system.slice/mysql.service
           └─20106 /usr/sbin/mysqld

Apr 02 21:46:42 webserver systemd[1]: Starting MySQL Community Server...
Apr 02 21:46:43 webserver systemd[1]: Started MySQL Community Server.

Start the server

If the previous command output the following information (note Active: inactive):

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Fri 2021-04-02 22:16:50 CEST; 3s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 20071 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
  Process: 20106 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
 Main PID: 20106 (code=exited, status=0/SUCCESS)
   Status: "Server shutdown complete"

Apr 02 21:46:42 webserver systemd[1]: Starting MySQL Community Server...
Apr 02 21:46:43 webserver systemd[1]: Started MySQL Community Server.
Apr 02 22:16:48 webserver systemd[1]: Stopping MySQL Community Server...
Apr 02 22:16:50 webserver systemd[1]: mysql.service: Succeeded.
Apr 02 22:16:50 webserver systemd[1]: Stopped MySQL Community Server.

then we can start the server with:

$ sudo systemctl start mysql

Restart the server

To apply any configuration file modification, you must restart the server with the following command:

$ sudo systemctl restart mysql

In Debian we have the following directory structure for the configuration files.

 /etc/mysql/
├── conf.d
│   └── mysql.cnf
├── my.cnf -> /etc/alternatives/my.cnf
├── my.cnf.fallback
├── mysql.cnf
└── mysql.conf.d
    └── mysqld.cnf   

Stop the server

$ sudo systemctl stop mysql

Automatic start

You can verify that MySQL will start after a system reboot by running the following command:

$ sudo systemctl is-enabled mysql
enabled

Connect to the server

# sudo mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.24 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> 
YouTube video

Administering MySQL from the command line, 3 (15)

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.