Skip to content

Instantly share code, notes, and snippets.

@irazasyed
Created August 2, 2025 20:17
Show Gist options
  • Save irazasyed/ab3182328e21db9d29ba8b177222e8bf to your computer and use it in GitHub Desktop.
Save irazasyed/ab3182328e21db9d29ba8b177222e8bf to your computer and use it in GitHub Desktop.
πŸ” Reset MySQL or MariaDB Root Access Without Password on macOS (Homebrew)

πŸ” Reset MySQL or MariaDB Root Access Without Password on macOS (Homebrew)

πŸ“Œ Problem

After installing MySQL or MariaDB via Homebrew on macOS, you might face:

  • No root password set by default
  • Forgotten root password
  • Need for passwordless root@localhost access for development tools (Laravel, Sequel Ace, TablePlus, etc.)

Typical error:

ERROR 1045 (28000): Access denied for user 'root'@'localhost'

βœ… Goal

Enable passwordless access to root@localhost on MySQL/MariaDB installed via Homebrew on macOS.


βš™οΈ Step-by-Step Fix

1. Create a Temporary Init SQL File

cat <<EOF > /tmp/init.sql
CREATE OR REPLACE USER 'root'@'localhost' IDENTIFIED BY '';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EOF

2. Stop Any Running Database Services

# For MariaDB
brew services stop mariadb

# For MySQL
brew services stop mysql

3. Start the Server with the Init Script

# For MariaDB
mariadbd --init-file=/tmp/init.sql --skip-networking --user=$(whoami)

# For MySQL
mysqld --init-file=/tmp/init.sql --skip-networking --user=$(whoami)

This bypasses login checks and runs the SQL commands directly.


4. Kill the Temp Server After Init (If Needed)

# MariaDB
pkill mariadbd

# MySQL
pkill mysqld

5. Start the Service Normally

# MariaDB
brew services start mariadb

# MySQL
brew services start mysql

6. Access MySQL/MariaDB as Root

mysql -u root

🧼 Cleanup

rm /tmp/init.sql

⚠️ Notes

  • Works only for localhost access.
  • Make sure your DB is not publicly accessible without a password.
  • Do not use in production without securing the root account.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment