CentOS Stream 9 is a rolling-release distribution that inherits the reliability and stability of CentOS while offering the latest features. If you’re using CentOS Stream 9 and need to set up MariaDB, an open-source, community-developed relational database management system, this step-by-step tutorial will guide you through the installation process.
Before you begin, ensure you have the following:
- A CentOS Stream 9 server with root or sudo access.
- An SSH client to connect to your server.
- A stable internet connection.
Step 1: Update Your System
Start by updating your CentOS Stream 9 system to ensure you have the latest security patches and software. Open a terminal and run the following commands:
sudo dnf update
This command will refresh your system’s package repository.
Step 2: Install MariaDB
CentOS Stream 9 includes MariaDB in its default repositories, simplifying the installation process. Use the following command to install MariaDB:
sudo dnf install mariadb-server mariadb-client
During the installation, you’ll be prompted to confirm the package installation. Type ‘y’ and press Enter.
Step 3: Start and Enable MariaDB
After installation, start the MariaDB service and enable it to start at boot using the following commands:
sudo systemctl start mariadb
sudo systemctl enable mariadb
You can verify that MariaDB is running with this command:
sudo systemctl status mariadb
Step 4: Secure Your MariaDB Installation
MariaDB comes with a script that helps you secure your database installation. Run the following command:
You’ll be prompted to set a root password, remove anonymous users, disallow root login remotely, and remove the test database. Follow the prompts and answer ‘Y’ or ‘N’ as needed.
Step 5: Log In to MariaDB
Now that your MariaDB installation is secure, you can log in to the database server using the following command:
mysql -u root -p
Enter the root password you set during the installation when prompted.
Step 6: Create a New Database and User
To create a new database and user, follow these steps:
Log in to MariaDB as the root user.
Create a new database (replace
mydatabasewith your preferred name):
CREATE DATABASE mydatabase;
Create a new user and grant privileges (replace
mypasswordwith your desired username and password):
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword'; GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost'; FLUSH PRIVILEGES;
Exit the MariaDB prompt:
Step 7: Test Your MariaDB Installation
You can test your new database and user by logging in with the created credentials:
mysql -u myuser -p
Enter the password when prompted, and you should now have access to the database you created.
You’ve successfully installed MariaDB on your CentOS Stream 9 server, secured the installation, and created a new database and user. MariaDB is a powerful and reliable database system that can serve as the foundation for various web applications and services. You are now ready to build and manage your databases with MariaDB on CentOS Stream 9.