DEV Community

Timo Reusch
Timo Reusch

Posted on

Set up MariaDB on macOS (quick)

1. Installing MariaDB Server

Using Homebrew, MariaDB Server can be installed easily:

brew install mariadb
Enter fullscreen mode Exit fullscreen mode

2. Start the server

mysql.server start
Enter fullscreen mode Exit fullscreen mode

You can also configure auto-start using Homebrew's services functionality:

brew services start mariadb

3. Login to the server

After the server is started, you can log in with the user mysql or as root sudo mysql -u root

4. Configure a database

Create a database

After logging into the server with the command above, execute

mysql> CREATE DATABASE your_database_name;
Enter fullscreen mode Exit fullscreen mode

Note, that the ; is mandatory!

Create a user

First create the user for localhost:

mysql> CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'Password123!';

mysql> GRANT ALL PRIVILEGES ON *.* TO 'app_user'@'localhost'
-> WITH GRANT OPTION;
Enter fullscreen mode Exit fullscreen mode

Next, create the user for an arbitrary server:

mysql> CREATE USER 'app_user'@'%' IDENTIFIED BY 'Password123!';

mysql> GRANT ALL PRIVILEGES ON *.* TO 'app_user'@'%'
-> WITH GRANT OPTION;
Enter fullscreen mode Exit fullscreen mode

Good to know
If any of the specified accounts, or any permissions for the specified accounts, already exist, then the server returns ERROR 1396 (HY000). If an error occurs, CREATE USER will still create the accounts that do not result in an error. Only one error is produced for all users which have not been created:

ERROR 1396 (HY000): Operation CREATE USER failed for 'u1'@'%','u2'@'%'

After completing those steps, the database is ready and should also be managable using e.g. Datagrip.


Related links: https://mariadb.com/kb/en/installing-mariadb-on-macos-using-homebrew/

Top comments (1)

Collapse
 
mfirmanakbar profile image
Firman

➜ ~ mysql.server start
Starting MariaDB
/opt/homebrew/Cellar/mariadb/11.5.2/bin/mysqld_safe: Deprecated program name. It will be removed in a future release, use 'mariadbd-safe' instead
240924 09:43:25 mysqld_safe Logging to '/opt/homebrew/var/mysql/firman-mac-m1pro.local.err'.
240924 09:43:25 mysqld_safe Starting mariadbd daemon with databases from /opt/homebrew/var/mysql
./opt/homebrew/bin/mysql.server: line 264: kill: (46220) - No such process
ERROR!