Install MySQL 8 on Debian 10 Buster

|
Published:
|
|

Welcome to our tutorial on how to install MySQL 8 on Debian 10 Buster.

Install MySQL 8 on Debian 10 Buster

In this guide, we are going to install MySQL 8 on Debian 10 Buster from the source code. As such, before you can continue, you need to install some required dependencies.

Install Required Dependencies

Since we are installing MySQL 8 from the source code, there are a number of build tools that are required for a successful build process.

apt install cmake libncursesw5-dev libncurses5-dev cmake build-essential libssl-dev pkg-config

Install Boost C++ Library.

As a required dependency, MySQL currently requires boost_1_69_0. You would however install from repos, but the available version is boost_1_67. Hence, you need to build Boost C++ from source code. Therefore, download it and build it and install it as shown below.

wget https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.gz -P /tmp
cd /tmp
tar xzf boost_1_69_0.tar.gz
cd boost_1_69_0
./bootstrap.sh --prefix=/usr/
./b2 
./b2 install

Create mysql User and Group

mysql user is required to run MySQL server.

useradd -r -M -s /bin/false mysql

Download MySQL 8 Source Code

Next, navigate to MySQL Download Area and download the generic Linux (Architecture Independent) MySQL 8 source code. You can simply run the command below to download MySQL 8.16.

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.16.tar.gz -P /tmp

Once the download is done, verify the integrity by comparing the MD5 checksums. The MD5 checksum of the downloaded archive should be: MD5: 06f16ed2dc84abeaa77c697c2d6f07e5

cd /tmp
md5sum mysql-8.0.16.tar.gz 
06f16ed2dc84abeaa77c697c2d6f07e5  mysql-8.0.16.tar.gz

If the integrity of the downloaded file passes, proceed to the next step.

Extract the Source Code

Once the download is done, extract the MySQL 8 archive. In this demo, MySQL tarball is downloaded to /tmp.

tar xzf mysql-8.0.16.tar.gz

Navigate to the extracted source directory and create MySQL 8 build directory.

cd mysql-8.0.16/
mkdir build

Next, navigate to the build directory just created and build it as shown below;

cd build
cmake ../../mysql-8.0.16

Next, run the make command to build the directory.

make

Install MySQL 8 on Debian 10 Buster

Once the compilation of MySQL is done, you can install it using the make install command.

make install

This will install MySQL under /usr/local/mysql.

Initialize MySQL 8 Data Directory

Once the installation is done, you need to initialize the data directory. Hence, navigate to MySQL installation directory.

cd /usr/local/mysql/

Next, create a MySQL directory for import and export operations. This directory will be used a value to the secure_file_priv system variable.

mkdir mysql-files

Set the user and group ownership of the the directory above to mysql. Also set the permissions of the directory to rwxr-x—.

chown mysql:mysql mysql-files
chmod 750 mysql-files

Next, initialize the database by executing the command below;

bin/mysqld --initialize --user=mysql
2019-07-20T12:56:06.835551Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.16) initializing of server in progress as process 11174
2019-07-20T12:56:10.680260Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: .qMkS;oEu8+(
2019-07-20T12:56:12.782049Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.16) initializing of server has completed

As you can see from the output, the initial temporary password of the root@localhost user is generated, A temporary password is generated for root@localhost: .qMkS;oEu8+(

Running MySQL 8

Copy MySQL startup files from the support-files directory to /etc/init.d.

cp support-files/mysql.server /etc/init.d/mysql

Reload the systemd manager configuration.

systemctl daemon-reload

Start MySQL.

systemctl start mysql

When mysql is run, systemd-sysv-generator will generate the /run/systemd/generator.late/mysql.service file. Copy this file to /etc/systemd/system.

cp /run/systemd/generator.late/mysql.service /etc/systemd/system

Edit the /etc/systemd/system/mysql.service.

export EDITOR=vim
systemctl edit mysql.service
[Install]
WantedBy=multi-user.target

Enable MySQL to run on system boot.

systemctl enable mysql

Add MySQL binary path your PATH environment.

export PATH=$PATH:/usr/local/mysql/bin/

Verify that MySQL is working as expected by connecting to it using the temporary password generated during initialization.

mysql -u root -p
Enter password: .qMkS;oEu8+(
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.16

Copyright (c) 2000, 2019, 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>

Once you login, reset the root password.

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyP@ssWord';

You can further confirm the version of MySQL by running the query.

SHOW VARIABLES LIKE "%version%";
+--------------------------+-------------------------------+
| Variable_name            | Value                         |
+--------------------------+-------------------------------+
| immediate_server_version | 999999                        |
| innodb_version           | 8.0.16                        |
| original_server_version  | 999999                        |
| protocol_version         | 10                            |
| slave_type_conversions   |                               |
| tls_version              | TLSv1,TLSv1.1,TLSv1.2,TLSv1.3 |
| version                  | 8.0.16                        |
| version_comment          | Source distribution           |
| version_compile_machine  | x86_64                        |
| version_compile_os       | Linux                         |
| version_compile_zlib     | 1.2.11                        |
+--------------------------+-------------------------------+
11 rows in set (0.02 sec)

MySQL initial Security

Next, you can run the initial security script, mysql_secure_installation to remove anonymous database users, disable remote root login and remove the test databases.

That is all on how to install MySQL 8 on Debian 10 Buster. Enjoy.

Related Tutorials;

Install MySQL 8 on FreeBSD 12

Install MySQL 8 on Debian 9

Install MySQL 8 on Fedora 30/Fedora 29

Install MariaDB 10 on Debian 10 Buster

Install MariaDB 10.4 on Ubuntu 18.04/Debian 9

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

2 thoughts on “Install MySQL 8 on Debian 10 Buster”

  1. After everything is installed, I cannot connect to the console tool, the user “root” is not authorized to log in, password or not.

    Reply
    • Hello Yanick
      When you start mysqld service and run any of the commands below as root user or with sudo;
      mysql
      or
      mysql -u root

      What error do you get?

      Reply

Leave a Comment