How to Install MariaDB on macOS: A Step-by-Step Tutorial

MariaDB is a popular open-source relational database management system that can be easily installed on macOS. In this step-by-step tutorial, we will guide you through the process of installing MariaDB on your macOS system.

Posted on

MariaDB is a popular open-source relational database management system that can be easily installed on macOS. In this step-by-step tutorial, we will guide you through the process of installing MariaDB on your macOS system.

Prerequisites

Before you begin, make sure you have:

  1. A macOS system (macOS 10.13 or later).
  2. Administrator privileges.
  3. An active internet connection.

Step 1: Install Homebrew

Homebrew is a package manager for macOS that will make installing MariaDB easy. If you don’t have Homebrew installed, open your Terminal and run the following command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Follow the instructions to complete the installation.

Step 2: Install MariaDB

Now that you have Homebrew, you can use it to install MariaDB. Run the following command in your Terminal:

brew install mariadb

Homebrew will download and install MariaDB along with its dependencies.

Step 3: Start MariaDB

After the installation is complete, you can start MariaDB with the following command:

brew services start mariadb

This will launch MariaDB as a background service, ensuring it starts automatically when you log in.

Step 4: Secure Your MariaDB Installation

MariaDB comes with a script that helps you secure your database installation. Run the following command:

mysql_secure_installation

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:

  1. Log in to MariaDB as the root user.

  2. Create a new database (replace mydatabase with your preferred name):

    CREATE DATABASE mydatabase;
    
  3. Create a new user and grant privileges (replace myuser and mypassword with your desired username and password):

    CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
    GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost';
    FLUSH PRIVILEGES;
    
  4. Exit the MariaDB prompt:

    exit;
    

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.

Conclusion

You’ve successfully installed MariaDB on your macOS system, 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 macOS.