Introduction:

When it comes to installing MariaDB on Arch Linux, you might encounter issues with conflicts and deprecation warnings, as I did. Additionally, much of the information available online might be outdated. This guide will help you navigate the installation process, provide essential configuration steps, and teach you how to manage users effectively. By the end, you'll have a secure and functional MariaDB setup on your Arch Linux system and be able to also use it to manage MySQL Database.

Step 1: System Upgrade

  • Before you begin, ensure your system is up to date by running the following command:
  •       sudo pacman -Syu
        

    Step 2: Installing MariaDB

  • Now, let's install MariaDB:
  •       sudo pacman -S mariadb
        

    Step 3: Initializing MariaDB

  • Initialize the MariaDB data directory using the following command:
  •       sudo mariadb-install-db --user=mysql --basedir=/usr
            --datadir=/var/lib/mysql
        

    Step 4: Starting and Managing MariaDB

  • To start the MariaDB server:
  •       sudo systemctl start mariadb
        
  • To stop it:
  •       sudo systemctl stop mariadb
        
  • To enable MariaDB to start at boot:
  •       sudo systemctl enable mariadb
        

    Step 5: Securing Your MariaDB Installation

    1. Run mariadb-secure-installation to secure your installation:
    2.         sudo mariadb-secure-installation
            
    3. You'll be prompted to set a new root password, remove anonymous users, disallow remote root login, and remove the test database. Follow the on-screen instructions.

    Creating a New User

    1. Log into the MariaDB command-line interface as the root user:
    2.         sudo mariadb
            
    3. Create a new user, replacing userName and yourPassword with your desired credentials:
    4.         CREATE USER 'userName'@'localhost' IDENTIFIED BY 'yourPassword';
            
    5. Grant all privileges to the new user, replacing userName:
    6.         GRANT ALL PRIVILEGES ON *.* TO 'userName'@'localhost' WITH GRANT
                OPTION;
            
    7. Flush privileges and exit the MariaDB client:
    8.         FLUSH PRIVILEGES; exit
            
    9. Log in with the newly created user (if needed):
    10.         mariadb -u userName -p
            
    11. Create a new database:
    12.         CREATE DATABASE yourDatabaseName;
            
    13. To view available databases:
    14.         SHOW DATABASES;
            

      Deleting a user

      If you created a user by mistake which i did and you want to remove it, you can use the following commands to delete the user:

      1. Log into the MariaDB command-line interface:
      2.           sudo mariadb
                
      3. Delete a user using the DROP USER statement, replacing userName:
      4.           DROP USER 'userName'@'localhost';
                
      5. After running the DROP USER command, flush the privileges:
      6.           FLUSH PRIVILEGES;
                
      7. Exit the MariaDB command-line interface:
      8.           exit
                

        Please use these commands with caution, as they are irreversible. Ensure you are deleting the correct user before proceeding.

        To Wrap It Up

        Installing and managing MariaDB on Arch Linux can be a straightforward process when you have the right guidance. By following the steps outlined in this guide, you can ensure that your MariaDB installation is up to date, secure, and tailored to your specific needs. From initializing the database to creating and managing users

        It's important to keep in mind that MariaDB is a powerful database management system, and it can serve a wide range of applications, from personal projects to enterprise-level solutions. With the knowledge gained from this guide, you are better equipped to harness the capabilities of MariaDB and make it work seamlessly within your Arch Linux system.

        As you continue your journey with MariaDB, remember to stay updated with best practices and security measures, and always exercise caution when making irreversible changes, such as deleting users or databases. With this newfound understanding, you can confidently use MariaDB to store, retrieve, and manage your data effectively on your Arch Linux system.