MySQL is a powerful, open-source relational database management system that has been a cornerstone of web development and server management for over two decades. Created in 1995, MySQL has evolved into a robust and highly scalable solution for managing large amounts of data, making it a top choice for businesses, organizations, and individuals worldwide.
With its compatibility with multiple operating systems, including Linux, and its strong security features, MySQL is ideal for use on a Rocky Linux server. Whether you’re building a dynamic web application, managing an e-commerce website, or working with big data, MySQL provides a versatile and reliable solution for your database management needs.
Features of MySQL:
- Relational database management system
- Open-source software
- Widely used in web development and server management
- Scalable solution for large amounts of data
- Supports multiple operating systems, including Linux
- Robust security features
- Easy to install and manage using the command line terminal.
This guide will guide you through installing MySQL 8.0 on your Rocky Linux 9 or Rocky Linux 8 system using the command line terminal. We’ll also cover how to secure your MySQL service, update it when necessary, and remove it if needed. By the end of this tutorial, you’ll be able to confidently and effectively manage your data with MySQL on Rocky Linux.
Table of Contents
Update Rocky Linux
Before installing MySQL on your Rocky Linux system, it is highly recommended that you ensure all existing packages are up-to-date. This will help to prevent any potential system conflicts during the installation process and maintain the overall health of your system.
sudo dnf upgrade --refresh
Method 1: Install MySQL 8.0 with Appstream
MySQL 8.0 is readily available as the default option in Rocky Linux. To install MySQL on your Rocky Linux system, run the following command in the terminal.
sudo dnf install mysql mysql-server
While there are several optional extra packages that you can install with MySQL on your Rocky Linux system, one popular alternative is to install both the developer kit and the standard MySQL installation. This option is specifically designed for developers who are building or testing applications and require access to the full suite of MySQL development tools.
sudo dnf install mysql mysql-server mysql-devel -y
It’s important to note that this option is not recommended for those using MySQL as a content management system or web server. It includes additional components that may not be necessary for these types of use cases. However, if you’re a developer looking to work with MySQL at a deeper level, the developer kit and standard installation option are excellent choices.
Once the installation of MySQL on your Rocky Linux system is complete, it is important to verify the installation to ensure that everything is functioning as expected. You can do this by using the following command in the terminal.
mysql --version
Once you have verified your MySQL 8.0 installation on your Rocky Linux system, activate the service and ensure that it starts automatically whenever your system boots up. To accomplish both of these tasks, you can use the following command in the terminal.
sudo systemctl enable mysqld --now
By using this command, you’ll be able to activate your MySQL 8.0 installation and ensure that it starts automatically whenever your system boots up. This is important for maintaining the accessibility and reliability of your data, as you’ll be able to access and manage your data without having to manually start the MySQL service every time you need to use it.
Method 2: Install MySQL 8.0 Community Edition
For those who require the latest version of MySQL, the following steps will guide you in accomplishing your goal. The first step is importing the official RPM package of the MySQL 8.0 community, which can be done by using the following command in the terminal.
Import MySQL 8.0 Community Edition for Rocky Linux 9:
sudo rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm
Import MySQL 8.0 Community Edition for Rocky Linux 8:
sudo rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el8-4.noarch.rpm
After importing the official RPM package of the MySQL 8.0 community, the next step is to install the MySQL 8.0 Community Server. To ensure that you’re installing the correct version, you’ll need to disable the App Stream version and enable the community edition. This can be done by using the following command in the terminal:
sudo dnf install --disablerepo=appstream mysql-community-server
Example output:
Now that you have installed the MySQL 8.0 Community Server directly from the MySQL RPM repository, the next step is to verify the success of the installation. This can be done by confirming the build version of your MySQL installation with the following command in the terminal.
mysql --version
Example output:
mysql Ver 8.0.32 for Linux on x86_64 (MySQL Community Server - GPL)
With the MySQL 8.0 Community Server successfully installed on your Rocky Linux system, the next step is to activate it. This can be done by using the following command in the terminal.
sudo systemctl enable mysqld --now
Check the Status of the MySQL 8.0
To verify the successful operation of your MySQL service, you can use the following systemctl status command in the terminal.
systemctl status mysqld
Example output:
By checking the status of your MySQL service, you can ensure that it’s up and running and ready for use. For new installations of MySQL 8.0 on your Rocky Linux system, the status of the service should be “OK.” The next step is to secure your MySQL instance with the service operational.
Here are some of the most commonly used system commands you will need to manage your MySQL systemd service.
Stop the MySQL service:
sudo systemctl stop mysqld
Start the MySQL service:
sudo systemctl start mysqld
Disable the MySQL service at system startup:
sudo systemctl disable mysqld
Activate the MySQL service at system startup:
sudo systemctl enable mysqld
Restart the MySQL service:
sudo systemctl restart mysqld
How to Secure MySQL 8.0
When installing MySQL 8.0 on your Rocky Linux system, the default security settings are often considered weak by industry standards, raising concerns about the potential for intrusion or exploitation by malicious actors. To address this issue, running the MySQL Installation Security script during the installation process is recommended.
To launch the MySQL Installation Security script (mysql_secure_installation), use the following command.
mysql_secure_installation
If you have installed the MySQL 8.0 Community version and encounter an error regarding the temporary password.
Error: Access denied for user 'root'@'localhost' (using password: NO)
As shown above, if you encounter a scenario where the root password for MySQL has already been set, you can use the following command to generate a temporary password and log into the MySQL Security script. During this process, you can set a new, secure password for your MySQL installation.
sudo grep 'temporary password' /var/log/mysqld.log
Example output with the new password generated:
2023-02-10T02:31:55.813212Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: dO064uBpgd)p
When logging into the MySQL Security script with your temporary password, you will be prompted to change it. This password is intended to be temporary and should be updated to a secure password as soon as possible.
Upon entering your password, you will be asked about the VALIDATE PASSWORD COMPONENT. This component involves setting password complexity checks to ensure the security of your MySQL installation. The default settings are typically sufficient, but you can adjust them to meet your specific security requirements.
An outline of the settings which you need to consider.
- Set a password for root accounts.
- Set a password for all accounts.
- Remove root accounts that are accessible from outside localhost.
- Remove anonymous user accounts.
- Remove the test database that is accessible by default to anonymous users.
Example of recommended settings:
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!
Additional Commands & Tips
Update MySQL 8.0
To check for updates on both versions of MySQL that were installed via the terminal using DNF repositories, use the following standard update command.
sudo dnf update --refresh
Remove (Uninstall) MySQL
To uninstall MySQL, use the following command to remove the database software and all its traces altogether.
sudo dnf remove mysql mysql-server
Users wishing to remove the Community Edition to scale back too, for example, the appstream version or delete the software, are ideal for removing all the RPM repositories.
sudo rm /etc/yum.repos.d/mysql-community*
Conclusion
In conclusion, installing MySQL 8.0 or the MySQL Community Edition on Rocky Linux is a straightforward process. By using the command line and the DNF repositories, you can easily install, verify, and secure your MySQL installation. In addition, updating and removing the software is just as simple, making it an excellent choice for users who require a reliable and flexible database management system.
Frequently Asked Questions
Q: What is the recommended method to install MySQL 8.0 on Rocky Linux – from the AppStream or using the MySQL 8.0 Community Edition?
A: The recommended method to install MySQL 8.0 on Rocky Linux is through the AppStream using the package manager. This is the easiest and quickest method and eliminates the need for manual steps and configurations. However, if you prefer to use the MySQL 8.0 Community Edition, you can follow the steps outlined in the article for a manual installation.
Q: How secure is MySQL on Rocky Linux?
A: MySQL on Rocky Linux is as secure as any other installation of the database management system, and the software is continuously updated with security patches and improvements. Best practices such as proper user management and secure configurations can be implemented to ensure the highest level of security for your MySQL installation on Rocky Linux.
Q: What are the key differences between MySQL and MariaDB on Rocky Linux?
A: MySQL and MariaDB are relational database management systems, but they have some key differences. MySQL is proprietary software owned by Oracle, while MariaDB is a community-driven fork of the MySQL project. MariaDB is designed to be fully compatible with MySQL and to remain free and open-source. The primary difference between the two is the ownership and governance of the software, and users should choose the database management system that best fits their needs and values.
Q: How popular is MySQL versus MariaDB on Rocky Linux?
A: Both MySQL and MariaDB are widely used database management systems, and their popularity depends on the specific use case and user preferences. MySQL is often used in large enterprise environments, while MariaDB is popular for small to medium-sized businesses and open-source projects. Both are available in the Rocky Linux AppStream and can be easily installed using the package manager, so users can choose the database management system that best fits their needs.