How to install and configure Mysql 8 on Rocky Linux/Alma Linux 9

MySQL is an open-source relational database management system. Its one of the popular relational management system.

Mysql is commonly installed as part of the popular LAMP or LEMP (Linux, Apache/Nginx, MySQL/MariaDB, PHP/Python/Perl) stack. It implements the relational model and Structured Query Language (SQL) to manage and query data.

In this guide we are going to install mysql 8 on Rocky Linux 9.

# Step 1 – Ensure that the system is up to date

Before proceeding, please ensure your system is up to date using this command:

sudo dnf update

# Step 2 – Installling mysql server

Lets search which packages provide mysql-server using this command:

$ sudo dnf search mysql-server

Last metadata expiration check: 3:12:52 ago on Fri Aug 26 00:18:30 2022.
============================================================= Name Exactly Matched: mysql-server =============================================================
mysql-server.x86_64 : The MySQL server and related files

Lets check the informattion of the package we found above using this command:

$ sudo dnf info mysql-server

Last metadata expiration check: 3:13:10 ago on Fri Aug 26 00:18:30 2022.
Available Packages
Name         : mysql-server
Version      : 8.0.28
Release      : 1.el9
Architecture : x86_64
Size         : 16 M
Source       : mysql-8.0.28-1.el9.src.rpm
Repository   : appstream
Summary      : The MySQL server and related files
URL          : http://www.mysql.com
License      : GPLv2 with exceptions and LGPLv2 and BSD
Description  : MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
             : client/server implementation consisting of a server daemon (mysqld)
             : and many different client programs and libraries. This package contains
             : the MySQL server and some accompanying files and directories.

Now lets Install the mysql-server package:

sudo dnf install -y mysql-server

To confirm the installed package:

$ rpm -qi mysql-server
Name        : mysql-server
Version     : 8.0.28
Release     : 1.el9
Architecture: x86_64
Install Date: Fri Aug 26 03:32:09 2022
Group       : Unspecified
Size        : 110489066
License     : GPLv2 with exceptions and LGPLv2 and BSD
Signature   : RSA/SHA256, Wed Jun  1 02:57:52 2022, Key ID 702d426d350d275d
Source RPM  : mysql-8.0.28-1.el9.src.rpm
Build Date  : Wed Jun  1 01:33:18 2022
Build Host  : pb-9649916b-cae2-4a7c-ae33-8b611c2271fa-b-x86-64
Packager    : Rocky Linux Build System (Peridot) <releng@rockylinux.org>
Vendor      : Rocky Enterprise Software Foundation
URL         : http://www.mysql.com
Summary     : The MySQL server and related files
Description :
MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
client/server implementation consisting of a server daemon (mysqld)
and many different client programs and libraries. This package contains
the MySQL server and some accompanying files and directories.

# Step 3 – Starting and enabling mysql service

Once installed. the service will not be enabled or started by default. Lets start the service:

sudo systemctl start mysqld

Then use the status command to confirm that it was started successfully:

$ sudo systemctl status mysqld
● mysqld.service - MySQL 8.0 database server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
     Active: active (running) since Fri 2022-08-26 03:33:57 UTC; 41s ago
    Process: 8038 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
    Process: 8060 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
   Main PID: 8166 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 9936)
     Memory: 433.8M
        CPU: 3.973s
     CGroup: /system.slice/mysqld.service
             └─8166 /usr/libexec/mysqld --basedir=/usr

Aug 26 03:33:50 local-kip-rocky9-srv systemd[1]: Starting MySQL 8.0 database server...
Aug 26 03:33:50 local-kip-rocky9-srv mysql-prepare-db-dir[8060]: Initializing MySQL database
Aug 26 03:33:57 local-kip-rocky9-srv systemd[1]: Started MySQL 8.0 database server.

Enable the service so it always starts when the server is rebooted using this command:

sudo systemctl enable mysqld

To view the MySQL 8 service log as follows using the journalctl command:

$ sudo journalctl -u mysqld -xe
$ sudo tail -f /var/log/mysql/mysqld.log

# Step 4 – Securing MySQL

MySQL includes a security script that allows you to change some default configuration options in order to improve MySQL’s security.

To use the security script, run the following command:

sudo mysql_secure_installation

This will take you through a series of prompts asking if you want to make certain changes to your MySQL installation’s security options. These options include:

  • setting up root user password
  • enabling the VALIDATE PASSWORD COMPONENT that ensures strong passwords are used
  • Removing anonymous users
  • Disabling root to login remotely
  • Removing test databases

Here is a sample output from my server:

$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT 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 component?

Press y|Y for Yes, any other key for No:
Please set the password for root here.

New password:

Re-enter new password:
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) :

 ... skipping.


Normally, root should only be allowed to connect from
'localhost'. This 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) :

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This 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) :

 ... skipping.
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) :

 ... skipping.
All done!

# Step 5 – Testing MySQL Installation

Let us check mysql version with this command:

$ mysql -V
mysql  Ver 8.0.28 for Linux on x86_64 (Source distribution)

Now you can Login as the root user and the password specified above.

$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.28 Source distribution

Copyright (c) 2000, 2022, 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> select version();
+-----------+
| version() |
+-----------+
| 8.0.28    |
+-----------+
1 row in set (0.00 sec)

mysql>

# Conclusion

In this guide we managed to install and configure mysql 8 on a Rocky linux 9 server.

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy