Skip to content

Instantly share code, notes, and snippets.

@petehouston
Created May 28, 2022 02:01
Show Gist options
  • Save petehouston/13bfc8cba1991cc6741fbe28cfa5491c to your computer and use it in GitHub Desktop.
Save petehouston/13bfc8cba1991cc6741fbe28cfa5491c to your computer and use it in GitHub Desktop.
homebrew mariadb reset root password

Quick guide to reset MariaDB root password on MacOS.

This tip can be used if you forget or want to change MariaDB root password.

Make sure to install MariaDB using Homebrew.

This tip is from Update root password in MariaDB 10.4 on MacOS

For MariaDB prior to v10.4

  • Stop currently running MariaDB server.
  • Start new instance with mysqld_safe --skip-grant-tables option.
  • Access to MariaDB from CLI, often being mysql.
  • Execute SQL query to change password.
UPDATE user SET password=PASSWORD('secret') WHERE User='root';

-- Or

UPDATE user SET authentication_string=PASSWORD('secret') WHERE User='root';

Final step is to execute FLUSH PRIVILEGES;.

For MariaDB v10.4+

  • Start MariaDB as usual via Homebrew brew services start mariadb
  • Launch mysql client with sudo: $ sudo mysql -u root. Make sure to have sudo; otherwise, it won't work.
  • Execute SQL query to change or reset root password.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'secret';

-- Or

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('secret');

Final step is to execute FLUSH PRIVILEGES;.

Want more coding tips and tricks?

Visit Pete Houston's blog for more coding tips and tricks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment