How to install local MariaDB on your Mac, Ubuntu, CentOS, Windows

This guide covers how to install a local MariaDB on your Mac, Ubuntu, CentOS, or Windows.

macOS

  1. Install Homebrew (if not already installed):

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

    brew install mariadb
  3. Start MariaDB service:

    brew services start mariadb

DMG Installer

  1. Download the MariaDB installer from the official website.
  2. Open the downloaded DMG file and follow the installation wizard.
  3. Start MariaDB from System Preferences or the command line:
    sudo mysql.server start

Troubleshooting on macOS

  • Socket error: If you get a socket error, check if MariaDB is running:

    brew services list

    Restart if needed:

    brew services restart mariadb
  • Connection refused: If you can't connect to the server:

    mysql.server start
  • Configuration file location: The default configuration file is at:

    • /usr/local/etc/my.cnf (if installed with Homebrew)
    • /etc/my.cnf (if installed with DMG)
  • Log file location: Check logs for detailed error messages:

    tail -f /usr/local/var/mysql/$(hostname).err

Ubuntu

apt

  1. Update the package index:

    sudo apt update
  2. Install MariaDB server:

    sudo apt install mariadb-server
  3. Start and enable MariaDB service:

    sudo systemctl start mariadb
    sudo systemctl enable mariadb

MariaDB Repository (For Latest Version)

  1. Import the MariaDB repository key:

    sudo apt-get install software-properties-common
    sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
  2. Add the MariaDB repository:

    sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://mirrors.xtom.com/mariadb/repo/10.6/ubuntu focal main'

    Note: Replace focal with your Ubuntu version codename and 10.6 with your desired MariaDB version.

  3. Update and install:

    sudo apt update
    sudo apt install mariadb-server

Troubleshooting on Ubuntu

  • Service won't start: Check for errors in the log:

    sudo journalctl -u mariadb
  • Permission issues: Ensure data directory has correct permissions:

    sudo chown -R mysql:mysql /var/lib/mysql
  • Configuration file location: Ubuntu typically stores configuration in:

    /etc/mysql/mariadb.cnf /etc/mysql/conf.d/ /etc/mysql/mariadb.conf.d/
  • Checking service status:

    sudo systemctl status mariadb
  • Reinstalling after problems:

    sudo apt purge mariadb-server mariadb-client
    sudo apt autoremove
    sudo rm -rf /var/lib/mysql
    sudo apt install mariadb-server

CentOS

Yum

  1. Create a MariaDB repository file:

    sudo vi /etc/yum.repos.d/MariaDB.repo
  2. Add the following content to the file:

    [mariadb] name = MariaDB baseurl = https://mirrors.xtom.com/mariadb/yum/10.6/centos8-amd64 gpgkey = https://mirrors.xtom.com/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck = 1

    Note: Replace centos8-amd64 with your CentOS version and architecture, and 10.6 with your desired MariaDB version.

  3. Install MariaDB:

    sudo yum install MariaDB-server MariaDB-client
  4. Start and enable MariaDB service:

    sudo systemctl start mariadb
    sudo systemctl enable mariadb

Troubleshooting on CentOS

  • Service fails to start: Check the system logs:

    sudo journalctl -u mariadb
  • SELinux issues: SELinux might block MariaDB from accessing needed resources. Check with:

    sudo ausearch -c 'mysqld' --raw

    To temporarily disable SELinux for testing:

    sudo setenforce 0
  • Firewall problems: If you can't connect remotely, check firewall settings:

    sudo firewall-cmd --permanent --add-service=mysql
    sudo firewall-cmd --reload
  • Configuration file location: The default configuration file is usually at:

    /etc/my.cnf /etc/my.cnf.d/mariadb-server.cnf
  • Completely reinstalling MariaDB:

    sudo systemctl stop mariadb
    sudo yum remove MariaDB-server MariaDB-client
    sudo rm -rf /var/lib/mysql
    # Then reinstall using the steps above

Windows

MSI

  1. Download the MSI installer from the official MariaDB website.

  2. Run the installer and follow these steps:

    • Accept the license agreement
    • Choose installation path (default is usually fine)
    • Set password for the root user
    • Configure service settings (recommended to run as a service)
    • Choose TCP port (default is 3306)
    • Set character set (UTF8 recommended)
    • Click Install to complete the process
  3. Verify the installation by opening Command Prompt and connecting:

    mysql -u root -p

Chocolatey

  1. Install Chocolatey (if not already installed):

    Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
  2. Install MariaDB:

    choco install mariadb

Troubleshooting on Windows

  • Service not starting: Check Windows Services (services.msc) and ensure MariaDB service is set to Automatic. If it fails to start:

    1. Open Event Viewer (eventvwr.msc)
    2. Check under Windows Logs > Application for MariaDB errors
  • Port conflict: If port 3306 is in use, edit my.ini file to change the port number:

    [mysqld]
    port=3307  # Change to any available port
  • Configuration file location: Check for the configuration file at:

    C:\Program Files\MariaDB\data\my.ini C:\ProgramData\MySQL\MySQL Server\my.ini
  • Log file access: Check logs for detailed error messages:

    C:\Program Files\MariaDB\data\MACHINENAME.err
  • Path issues: If the 'mysql' command isn't recognized, add it to your PATH:

    1. Right-click on This PC > Properties > Advanced system settings > Environment Variables
    2. In System Variables, find PATH, click Edit
    3. Add C:\Program Files\MariaDB\bin (adjust if installed in different location)
    4. Click OK and restart Command Prompt

Initial Configuration

After installation, it's important to secure your MariaDB installation:

  1. Run the security script:

    • On Linux/macOS:
      sudo mysql_secure_installation
    • On Windows (Command Prompt as Administrator): mysql_secure_installation
  2. Follow the prompts to:

    • Set a root password (if not already set)
    • Remove anonymous users
    • Disallow root login remotely
    • Remove test database
    • Reload privilege tables

Verifying Your Installation

To install MariaDB client, you can refer to this post.

To verify your MariaDB installation:

  1. Connect to MariaDB:

    mariadb -u root -p

    Enter your password when prompted.

  2. Check the version:

    SELECT VERSION();
  3. Create a test database:

    CREATE DATABASE test_db;
    USE test_db;
    CREATE TABLE test_table (id INT, name VARCHAR(50));
    INSERT INTO test_table VALUES (1, 'Test Data');
    SELECT * FROM test_table;
  4. Exit MariaDB:

    EXIT;
Edit this page on GitHub