How To Install MySQL on CentOS Stream 10
In this tutorial, we will show you how to install MySQL on CentOS Stream 10. MySQL is a powerful and widely-used relational database management system (RDBMS) that serves as the backbone for many applications, from small websites to large enterprise solutions. Installing MySQL on CentOS Stream 10 can enhance your server’s capabilities, providing a robust platform for data management. This article will guide you through the process of installing MySQL on CentOS Stream 10, ensuring a smooth setup with step-by-step instructions and troubleshooting tips.
Understanding CentOS Stream 10 and MySQL
What is CentOS Stream 10?
CentOS Stream 10 is a rolling-release distribution that sits between the traditional CentOS and Red Hat Enterprise Linux (RHEL). It provides a preview of what the next minor RHEL version will look like, making it ideal for developers and system administrators who want to stay ahead of the curve. With a five-year lifecycle, CentOS Stream 10 is designed to receive continuous updates and enhancements, ensuring that users have access to the latest features and security patches.
What is MySQL?
MySQL is an open-source RDBMS that allows users to create, manage, and manipulate databases. It is known for its reliability, performance, and ease of use. MySQL supports various storage engines, including InnoDB and MyISAM, which provide flexibility depending on the application’s needs. Its extensive documentation and active community make it a popular choice among developers.
Pre-Installation Requirements
System Requirements
- A server running CentOS Stream 10.
- At least 1 GB of RAM (2 GB recommended for production environments).
- Minimum of 20 GB of free disk space.
Software Requirements
You will need to ensure that your system has the necessary packages installed. The default package manager for CentOS is DNF (Dandified YUM), which simplifies package management.
User Privileges
You must have root or sudo privileges to install software on your server. If you’re not logged in as root, prepend commands with sudo
.
Step-by-Step Installation Guide
Step 1: Update Your System
The first step in installing MySQL is to ensure your system is up-to-date. Run the following command:
sudo dnf update -y
This command updates all installed packages to their latest versions, ensuring compatibility with MySQL.
Step 2: Add the MySQL Yum Repository
The next step is to add the official MySQL Yum repository to your system. This repository contains the necessary packages to install MySQL easily. Execute the following commands:
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
sudo dnf localinstall mysql80-community-release-el7-3.noarch.rpm -y
This command downloads and installs the repository configuration package. After installation, verify that the repository has been added successfully:
dnf repolist enabled | grep "mysql.*-community.*"
Step 3: Install MySQL Server
With the repository configured, you can now install MySQL Server using DNF:
sudo dnf install mysql-server -y
This command installs the latest version of MySQL Server along with its dependencies. Once completed, you should see a message indicating successful installation.
Step 4: Start the MySQL Service
After installation, you need to start the MySQL service manually:
sudo systemctl start mysqld
You can check the status of the service using:
sudo systemctl status mysqld
If it shows “active (running),” then your MySQL service has started successfully.
Step 5: Secure MySQL Installation
The next crucial step is securing your MySQL installation. Run the security script provided by MySQL:
sudo mysql_secure_installation
This script guides you through several security-related tasks:
- Setting a root password.
- Removing anonymous users.
- Disallowing root login remotely.
- Removing test databases.
- Reloading privilege tables.
Step 6: Verify MySQL Installation
You can verify that MySQL was installed correctly by logging into the MySQL shell:
mysql -u root -p
You will be prompted for the root password you set during the secure installation process. Once logged in, you can check the version with:
SELECT VERSION();
Post-Installation Configuration
Enabling MySQL to Start at Boot
If you want MySQL to start automatically when your server boots up, run this command:
sudo systemctl enable mysqld
Create a New Database and User
You may want to create a new database and user for your applications. Here’s how:
Create database mydatabase;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
Troubleshooting Common Issues
- Error: “mysql: command not found”: This usually means that MySQL was not installed correctly or that your PATH variable does not include the directory where mysql is located. Ensure you followed all installation steps correctly.
- Error: “MySQL service doesn’t start”: Check if there are any conflicting services running on port 3306 (the default port for MySQL). Use
netstat -tuln | grep 3306
. If another service is using this port, stop it or change its configuration. - Error: “Access denied for user ‘root'”: If you’re unable to log in as root, ensure you’re using the correct password set during installation. You may also need to reset your root password if forgotten.
- Error: “InnoDB initialization failed”: This could be due to insufficient disk space or corrupted files from previous installations. Clear old data files if necessary and ensure enough space is available on your disk.
Congratulations! You have successfully installed MySQL. Thanks for using this tutorial for installing the MySQL database on your CentOS Stream 10 system. For additional or useful information, we recommend you check the official MySQL website.