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'
Enable passwordless access to root@localhost
on MySQL/MariaDB installed via Homebrew on macOS.
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
# For MariaDB
brew services stop mariadb
# For MySQL
brew services stop mysql
# 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.
# MariaDB
pkill mariadbd
# MySQL
pkill mysqld
# MariaDB
brew services start mariadb
# MySQL
brew services start mysql
mysql -u root
rm /tmp/init.sql
- 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.