This tutorial will guide you through the process of creating a database, database user, and connecting to it in AlmaLinux using the popular
MariaDB database server.
- Access to an AlmaLinux server with root privileges
- A terminal emulator program
1. Installing MariaDB:
Open a terminal window and type the following command to install MariaDB:
sudo dnf install mariadb-server
Enter your root password when prompted and press Enter. The installation process will begin.
2. Starting and Enabling MariaDB:
Once the installation is complete, start the MariaDB service:
sudo systemctl start mariadb
Enable MariaDB to start automatically at boot:
sudo systemctl enable mariadb
3. Securing MariaDB:
It’s crucial to secure your MariaDB installation by running the following command:
Follow the on-screen instructions to set a strong root password, remove anonymous users, and restrict remote root logins.
4. Creating a Database:
Log in to the MariaDB console using the root user and password you set:
sudo mysql -u root -p
Create a new database named
CREATE DATABASE mydatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
5. Creating a Database User:
Create a new database user named
dbuser with a strong password:
CREATE USER dbuser@localhost IDENTIFIED BY 'strongpassword';
dbuser user all privileges on the
GRANT ALL PRIVILEGES ON mydatabase.* TO dbuser@localhost;
Flush privileges to apply the changes:
6. Connecting to the Database:
You can now connect to the
mydatabase database using the
dbuser user from any application that supports MariaDB.
Here’s an example using the
mysql command-line tool:
mysql -u dbuser -p -D mydatabase
Enter the database user’s password when prompted.
7. Additional Configurations (Optional):
- Remote Access: If you want to connect to your database from another server, you need to configure your firewall to allow incoming connections on port 3306.
- Client Applications: Download and install a suitable database client application for your operating system and configure it to connect to your MariaDB server.
Congratulations! You have successfully created a database, a database user, and connected to it in AlmaLinux. You can now start using your database for your applications.