How to Set Up MariaDB on macOS

Galaxy Glossary

How do I set up MariaDB on macOS using Homebrew?

Install and configure MariaDB locally on macOS using Homebrew, then connect and create sample ecommerce tables.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

How do I install MariaDB with Homebrew?

Run brew install mariadb to download and compile the latest stable MariaDB package. Homebrew handles dependencies automatically, ensuring a clean installation.

How do I start and autostart the server?

Launch MariaDB immediately with brew services start mariadb. This command also registers MariaDB as a launch agent so it boots automatically after each macOS restart.

How do I secure the root account?

Harden the server by running mysql_secure_installation. The wizard lets you set a strong root password, remove anonymous users, disallow remote root logins, and drop the test database.

How do I connect from the terminal?

Use mysql -u root -p, then enter the password you just set. You’ll land in the MariaDB shell ready to run SQL.

How do I create an ecommerce database and user?

Execute: CREATE DATABASE ecommerce; followed by CREATE USER 'shop_admin'@'localhost' IDENTIFIED BY 'StrongPass1!'; and GRANT ALL PRIVILEGES ON ecommerce.* TO 'shop_admin'@'localhost';.

How do I load sample tables quickly?

Switch to the new database with USE ecommerce; and paste the table definitions in the next section. Having realistic data structures accelerates local testing.

What are best practices after installation?

Enable slow-query logging (SET GLOBAL slow_query_log = 1;) and adjust innodb_buffer_pool_size to 50-70% of system RAM for better performance. Always back up /usr/local/var/mysql with Time Machine or a scheduled mysqldump.

Which Homebrew options matter?

--build-from-source compiles fully on your machine, while --with-openssl links against OpenSSL for TLS 1.3 support. Most users can omit them; the default bottle works fine.

Where are the config files?

Main configuration lives in /usr/local/etc/my.cnf. Override server settings in [mysqld], then restart the service to apply changes.

Why How to Set Up MariaDB on macOS is important

How to Set Up MariaDB on macOS Example Usage


-- List last week's orders with customer names and totals
SELECT c.name,
       o.id AS order_id,
       o.order_date,
       o.total_amount
FROM Orders o
JOIN Customers c ON c.id = o.customer_id
WHERE o.order_date >= CURDATE() - INTERVAL 7 DAY
ORDER BY o.order_date DESC;

How to Set Up MariaDB on macOS Syntax


# Homebrew install (latest stable)
brew install mariadb [--build-from-source] [--with-openssl]

# Start service and enable autostart
brew services start mariadb

# Secure installation wizard
mysql_secure_installation

# Terminal connection as root
mysql -u root -p

# Sample ecommerce schema setup
CREATE DATABASE ecommerce;
USE ecommerce;

CREATE TABLE Customers (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(100),
  email VARCHAR(150) UNIQUE,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE Orders (
  id INT AUTO_INCREMENT PRIMARY KEY,
  customer_id INT,
  order_date DATE,
  total_amount DECIMAL(10,2),
  FOREIGN KEY (customer_id) REFERENCES Customers(id)
);

CREATE TABLE Products (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(120),
  price DECIMAL(10,2),
  stock INT
);

CREATE TABLE OrderItems (
  id INT AUTO_INCREMENT PRIMARY KEY,
  order_id INT,
  product_id INT,
  quantity INT,
  FOREIGN KEY (order_id) REFERENCES Orders(id),
  FOREIGN KEY (product_id) REFERENCES Products(id)
);

Common Mistakes

Frequently Asked Questions (FAQs)

Do I need Rosetta for Apple Silicon?

No. Homebrew distributes native ARM64 bottles for MariaDB, so installation works without Rosetta translation.

How do I upgrade MariaDB later?

Run brew upgrade mariadb, then execute mysql_upgrade to update system tables.

Can I run MySQL and MariaDB together?

Technically yes by changing port numbers, but avoid it. Running both can cause socket conflicts and double your RAM usage.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie
BauHealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.