Friday, November 15, 2024
Google search engine
HomeData Modelling & AIHow to Install MySQL on CentOS 8

How to Install MySQL on CentOS 8

Introduction

MySQL is a database management application. It is part of the LAMP (Linux, Apache, MySQL, PHP) stack that powers much of the internet.

This guide will show you how to install MySQL 8.0 on CentOS 8.

tutorial on Installing MySQL 8 on CentOS 8tutorial on Installing MySQL 8 on CentOS 8

Prerequisites

  • A system running CentOS 8
  • Access to a terminal window / command line (Ctrl-Alt-F2)
  • Sudo or root privileges

Installing MySQL 8.0 on CentOS 8

Install MySQL from AppStream

With the release of CentOS version 8, many popular software packages were bundled into the AppStream repository.

To install MySQL from AppStream, make sure the repository is enabled first:

subscription-manager repos ––list-enabled

You should see a list of the different repositories enabled on your system. Check the repo names and make sure that AppStream is on the list.

Note: Your CentOS 8 system might not have subscription-manager installed. If that is the case, the system will prompt you to install the service. Type Y and hit Enter.

Next, use the DNF package manager to install MySQL:

sudo dnf install @mysql 

When prompted, type Y and hit Enter to allow the operation to finish.

One advantage of installing MySQL using AppStream is simplicity. However, sometimes the software version in the repositories can be outdated. If you need to install the latest version of MySQL, try installing MySQL from the developer’s repository.

Install MySQL – Developer Community Edition

If you need the latest or a specific version of MySQL, use this step. Often, software developers release newer versions faster than they are uploaded to the default Linux repositories. In this step, we bypass the default repository and install straight from the developer’s repository.

Start by enabling the MySQL developer repository. Enter the following into a terminal window:

rpm –ivh https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
Command to add support for the official MySQL repositoryCommand to add support for the official MySQL repository

Note: If you need a different version of MySQL, use the actual name of the repository you want to use. The name can be found on the MySQL Repository Setup Package page.

Verify the repository was correctly added:

yum repolist all | grep mysql
Verification that the MySQL Community repository installed on CentOS 8Verification that the MySQL Community repository installed on CentOS 8

Temporarily disable the AppStream repository and install MySQL from the developer’s repository:

sudo yum ––disablerepo=AppStream install –y mysql-community-server
disable AppStream repository and install MySQL from repositorydisable AppStream repository and install MySQL from repository

Allow the process to finish. Re-enable the AppStream repository once finished:

sudo yum ––enablerepo=AppStream

Managing the MySQL Service on CentOS 8

MySQL is a software service that runs in the background of your system. Like with other software services, you control it by using the systemctl command.

If you are new to MySQL, also consider learning about regular admin tasks such as listing all databases, listing users in a MySQL database, how to rename a database or allowing remote connections.

Start and Enable MySQL Service

Start the MySQL service:

sudo systemctl start mysqld

Set MySQL to start on boot:

sudo systemctl enable mysqld

Check the status of the MySQL service:

sudo systemctl status mysqld
Terminal output in CentOS when MySQL is active and enabled.Terminal output in CentOS when MySQL is active and enabled.

Stop and Disable MySQL Service

You can stop the MySQL service with the following:

sudo systemctl stop mysqld

Prevent the MySQL service from starting at boot:

sudo systemctl disable mysqld
MySQL status inactive and disabled at boot in CentOS 8MySQL status inactive and disabled at boot in CentOS 8

Securing MySQL

The default MySQL installation lacks many common security features. It is recommended that you run the secure installation script to enable security features.

These features include removing anonymous user support, disabling remote login, and defining a new MySQL root password.

1. Start by displaying the temporary (default) root password:

cat /var/log/mysqld.log | grep -i 'temporary password'

The system shows the temporary password. Make note of it.

2. Next, run the security script by entering the following:

sudo mysql_secure_installation

The system will now walk you through your security configuration.

Note: Upon running the mysql_secure_installation, you may receive an Access denied for user ‘root’@’localhost‘ error message. Follow instructions in How to Resolve Access Denied For User Root@Localhost if that occurs.

3. You may get a prompt asking if you want to use the VALIDATE PASSWORD PLUGIN. This plugin tests the strength of passwords. We recommend to press Y and specify the level of password validation policy (Low, Medium, or Strong).

mysql_secure_installation script execution in the terminalmysql_secure_installation script execution in the terminal

4. On the prompt, enter and re-enter a new password for the root MySQL user.

5. When asked if you want to continue using the password you just provided – select Y to set the password.

6. The next prompt asks if you want to remove anonymous users. Y is the setting we recommend.

7. Select Y on the prompt to disallow remote root login. Allowing root access from localhost only is a security best practice.

8.  Type Y to remove the test database. We recommend this setting since anyone can access the test database, and this is why you should remove it from production environments.

9. Finally, enter Y to reload all privilege tables. This action confirms the changes you made.

Note: Your work environment may vary. If you require access to one of these features, leave the default setting. Please refer to your MySQL support staff to develop security solutions for your custom environment.

Conclusion

You should now have a working installation of MySQL on your CentOS 8 system. Consider MySQL performance tuning best practices whenever working with databases.

Was this article helpful?
YesNo

RELATED ARTICLES

Most Popular

Recent Comments