How To Install MariaDB on CentOS Stream 10
MariaDB is a powerful, open-source relational database management system that is widely used for web applications, data storage, and various other purposes. As a fork of MySQL, it offers enhanced features and performance, making it a popular choice among developers and system administrators. This guide will walk you through the steps to install MariaDB 11 on CentOS Stream 10, ensuring that you have a robust database solution at your fingertips.
Prerequisites
Before diving into the installation process, it’s essential to ensure that your system meets the necessary requirements. This section outlines the hardware and software prerequisites for installing MariaDB 11.
System Requirements
- Minimum Hardware Specifications:
- 1 GHz processor or higher
- 1 GB RAM (2 GB recommended)
- 20 GB free disk space
- Recommended Specifications:
- Multi-core processor
- 4 GB RAM or more
- SSD storage for better performance
Software Requirements
- CentOS Stream 10: Ensure that you have CentOS Stream 10 installed on your machine.
- Sudo Privileges: You need access to a terminal with sudo privileges to install packages and make system changes.
Preparing Your System
Once you’ve confirmed that your system meets the requirements, the next step is to prepare it for the installation of MariaDB.
Updating the System
Keeping your system updated is crucial for security and compatibility. Run the following command to update existing packages:
sudo dnf update
This command ensures that all installed packages are up-to-date, reducing the chances of encountering issues during installation.
Installing Required Dependencies
MariaDB may require certain dependencies to function correctly. Install any necessary dependencies using the following command:
sudo dnf install -y wget curl
This command installs wget and curl, which are useful for downloading files and transferring data over networks.
Adding the MariaDB Repository
The next step is to add the official MariaDB repository to your system. This allows you to install MariaDB using the DNF package manager.
Understanding YUM Repositories
The Yellowdog Updater, Modified (YUM) is a package management utility for RPM-compatible Linux distributions. It simplifies the process of installing and managing software packages.
Creating the MariaDB Repository File
Create a repository file for MariaDB by running:
sudo nano /etc/yum.repos.d/mariadb.repo
This command opens a text editor where you can add repository details.
Adding Repository Details
Add the following configuration to the file:
[mariadb]
name=MariaDB
baseurl=https://downloads.mariadb.org/mariadb/repositories/11.0/centos10/x86_64/
gpgkey=https://downloads.mariadb.org/mariadb/repositories/11.0/centos10/x86_64/RPM-GPG-KEY-mariadb
gpgcheck=1
enabled=1
This configuration specifies where to find MariaDB packages and ensures that they are verified with a GPG key for security.
Installing MariaDB
With the repository added, you can now proceed to install MariaDB 11 on your CentOS Stream 10 system.
Using DNF to Install MariaDB
The installation process is straightforward. Use the following command to install both the MariaDB server and client:
sudo dnf install mariadb-server mariadb-client
This command will download and install MariaDB along with its client utilities.
Verifying Installation
After installation, verify that MariaDB has been installed correctly by checking its version:
mysql --version
If installed successfully, this command will display the version of MariaDB you just installed.
Starting and Enabling the MariaDB Service
The next step is to start the MariaDB service and ensure it runs automatically at boot time.
Starting the Service
You can start the MariaDB service using this command:
sudo systemctl start mariadb
This command initiates the database service, making it ready for use.
Enabling Service at Boot
If you want MariaDB to start automatically when your system boots up, run:
sudo systemctl enable mariadb
Checking Service Status
You can verify that the service is running by checking its status with this command:
sudo systemctl status mariadb
If everything is set up correctly, you should see an output indicating that the service is active (running).
Securing Your MariaDB Installation
Running mysql_secure_installation
The mysql_secure_installation
script assists in securing your installation by allowing you to set a root password and remove unnecessary users and databases. Run this script with:
sudo mysql_secure_installation
This command will prompt you through several security-related questions. Follow these steps during execution:
- Create a root password?: Set a strong password for your root user.
- Remove anonymous users?: Yes, this enhances security by preventing unauthorized access.
- Disallow root login remotely?: It’s advisable to answer “yes” unless remote access is necessary.
- Remove test database?: Yes, this database can be safely removed as it poses a security risk.
- Reload privilege tables?: Confirm this action to apply all changes made during this process.
Create a Database and User
You are now ready to create your first database and user in MariaDB. This section provides step-by-step instructions on how to do so effectively.
Logging into MariaDB
To log into your newly installed MariaDB server as root, use:
mysql -u root -p
You will be prompted for the root password you set earlier.
Create a New Database
Once logged in, create a new database using SQL commands:
CREATE DATABASE example_db;
This command creates a new database named “example_db
“. You can replace “example_db
” with any name of your choice.
Create a User and Grant Privileges
Next, create a new user who will have access to this database:
CREATE USER 'example_user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON example_db.* TO 'example_user'@'localhost';
FLUSH PRIVILEGES;
In this example:
– Replace ‘example_user
‘ with your desired username.
– Replace ‘password
‘ with a strong password.
– The GRANT statement gives full privileges on “example_db
” to “example_user
“.
Troubleshooting Common Issues
Even with careful execution of each step, issues may arise during installation or configuration. Here are some common problems and their solutions:
- Error: “Unable to locate package”: This may occur if there’s an issue with your repository configuration. Double-check that you’ve added the correct URL in
/etc/yum.repos.d/mariadb.repo
. - Error: “Service not found”: If you receive an error when trying to start or enable the service, ensure that you’ve installed both mariadb-server and mariadb-client correctly.
- Error: “Access denied”: If you encounter access issues when logging in as root or another user, ensure that you’ve granted privileges correctly using GRANT statements.
- Error: “Can’t connect to local MySQL server”: This indicates that the service may not be running. Check its status using
sudo systemctl status mariadb
. - If problems persist after trying these solutions, consider checking logs located in
/var/log/mariadb/
for more detailed error messages.
Congratulations! You have successfully installed MariaDB. Thanks for using this tutorial for installing MariaDB database server on CentOS Stream 10 system. For additional help or useful information, we recommend you check the official MariaDB website.