How to Install MySQL 8.0 on CentOS 9 Stream


MySQL is a relational database management system based on SQL (Structured Query Language). It is one of the most widely used database software for several well-known applications. MySQL is used for data warehousing, e-commerce, and logging applications, but its more commonly used feature is web database storage and management.

In the following tutorial, you will learn how to install MySQL 8.0 Community edition on CentOS 9 Stream using the command line terminal with instructions on how to secure the MySQL service, update, and, if necessary remove.

Situational – Remove DNF Subscription Manager

For users who encounter issues with “This system is not registered with an entitlement server. You can use subscription-manager to register,” then use the following command to remove the subscription manager as it is unnecessary for CentOS stream to receive updates, unlike RHEL.

sudo dnf erase subscription-manager -y

Example output:

How to Install Tor Browser on CentOS 9 Stream

As mentioned above, all the subscription-based lockouts have been removed.

Advertisement


Update CentOS Stream

Before you continue, your system is advised to ensure all existing packages are up to date to avoid system conflicts during the installation and good system maintenance.

sudo dnf upgrade --refresh -y

Install MySQL 8.0

By default, MySQL 8.0 is available as the default choice in CentOS Stream and is entirely up to date. Run the following command to install MySQL 8.0 community server.

sudo dnf install mysql mysql-server -y

While there are quite a few options, you can include, another popular option is installing the developer kit and standard MySQL installation.

Note this is only for developers, not CMS/Webserver users.

sudo dnf install mysql mysql-server mysql-devel -y

When the installation is complete, verify the installation using the --version command.

mysql --version

Example output:

Advertisement


How to Install MySQL 8.0 on CentOS 9 Stream

Then activate MySQL 8 using the following command.

sudo systemctl enable mysqld --now

The above command will start MySQL in your current session and, on future systems, restart automatically.

See also  How to Install Linux Kernel 6.0 on CentOS 9 Stream | CentOS 8 Stream

Check the Status of the MySQL 8.0

The installer will automatically start your default MySQL service and configure itself to start automatically on system startup. To verify that your MySQL service is operational after installation, type the following  systemctl command :

systemctl status mysqld

Example output:

How to Install MySQL 8.0 on CentOS 9 Stream

To stop the MySQL service:

sudo systemctl stop mysqld

To start the MySQL service:

Advertisement


sudo systemctl start mysqld

To disable the MySQL service at system startup:

sudo systemctl disable mysqld

To activate the MySQL service at system startup:

sudo systemctl enable mysqld

To restart the MySQL service:

sudo systemctl restart mysqld

Secure MySQL 8.0

When installing MySQL, the new defaults are considered weak by most standards and raise concerns about the potential of allowing intrusion or exploitation by hackers. One solution is to run the installation security script with the MySQL installation.

First, use the following command to launch the  (mysql_secure_installation) :

sudo mysql_secure_installation

Skip the temporary password command; read this quick tip if you have an issue.

Advertisement


By default, the root password should be blank. If the password has been set for some reason, use the following command to generate a temporary password to log into the MySQL Security script. During configuration, you will set a new password.

sudo grep 'temporary password' /var/log/mysqld.log

Next, you will be prompted for your root password, and then you will see a question about VALIDATE PASSWORD COMPONENT; this involves defining password complexity checks; for the most part, the default is correct.

Then follow below:

  • Setting the password for root accounts.
  • Setting the password for the accounts.
  • Removal of root accounts accessible from outside the local host.
  • Removal of anonymous user accounts.
  • Removal of the test database, accessible by default to anonymous users.

Be careful; you use (Y) to delete everything. In addition, if you wish, you can reset your root password by creating a new one; you can ignore it if you want, as you already set it during the initial installation with the pop-ups.

See also  How to Install Htop on Arch Linux

Example:

[joshua@centos-9-stream ~]$ mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 

The existing password for the user account root has expired. Please set a new password.

New password: <---- SET NEW PASSWORD

Re-enter new password: <---- RE-ENTER NEW PASSWORD

Re-enter new password: 
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY (SKIP IF YOU ALREADY JUST SET)

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY.
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) : Y <---- Type Y then press the ENTER KEY.
Success.


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) : Y <---- Type Y then press the ENTER KEY.
Success.

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) : Y <---- Type Y then press the ENTER KEY.
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

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) : Y <---- Type Y then press the ENTER KEY.
Success.

All done! 

How to Remove (Uninstall) MySQL 8.0

If you no longer want to use the MySQL database and want to delete it entirely, run the following command:

Advertisement


sudo dnf autoremove mysql mysql-server

The above command will blanket cover removing dependencies no longer required.

See also  How to Install SMPlayer on Debian 11 Bullseye

Comments and conclusion

In the tutorial, you learned how to install the latest version of MySQL 8 on CentOS 9 Stream. Additionally, as well as optimization options for specific workloads on specific hardware by mapping user threads to processors, just a few of the new features.

Overall, MySQL 8 provides better performance for read/write workloads, I/O-related workloads, and high contention workloads. Users of older versions of MySQL should consider upgrading, as the performance gains are well worth it.


Not what you were looking for? Try searching for additional tutorials.

Leave a Comment