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
Homebrew (Recommended)
-
Install Homebrew (if not already installed):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
Install MariaDB:
brew install mariadb
-
Start MariaDB service:
brew services start mariadb
DMG Installer
- Download the MariaDB installer from the official website.
- Open the downloaded DMG file and follow the installation wizard.
- 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
-
Update the package index:
sudo apt update
-
Install MariaDB server:
sudo apt install mariadb-server
-
Start and enable MariaDB service:
sudo systemctl start mariadb sudo systemctl enable mariadb
MariaDB Repository (For Latest Version)
-
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'
-
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 and10.6
with your desired MariaDB version. -
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
-
Create a MariaDB repository file:
sudo vi /etc/yum.repos.d/MariaDB.repo
-
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, and10.6
with your desired MariaDB version. -
Install MariaDB:
sudo yum install MariaDB-server MariaDB-client
-
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
-
Download the MSI installer from the official MariaDB website.
-
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
-
Verify the installation by opening Command Prompt and connecting:
mysql -u root -p
Chocolatey
-
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'))
-
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:
- Open Event Viewer (eventvwr.msc)
- 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:
- Right-click on This PC > Properties > Advanced system settings > Environment Variables
- In System Variables, find PATH, click Edit
- Add
C:\Program Files\MariaDB\bin
(adjust if installed in different location) - Click OK and restart Command Prompt
Initial Configuration
After installation, it's important to secure your MariaDB installation:
-
Run the security script:
- On Linux/macOS:
sudo mysql_secure_installation
- On Windows (Command Prompt as Administrator):
mysql_secure_installation
- On Linux/macOS:
-
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:
-
Connect to MariaDB:
mariadb -u root -p
Enter your password when prompted.
-
Check the version:
SELECT VERSION();
-
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;
-
Exit MariaDB:
EXIT;