如果您在 Mojave、Catalina、Big Sur 以及现在在 macOS Monterey 上运行:
brew install mariadb
...
brew services start mariadb
==> Successfully started `mariadb` (label: homebrew.mxcl.mariadb)
$(brew --prefix mariadb)/bin/mysqladmin -u root password newpass
/usr/local/opt/mariadb/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost''
使用 root 帐户登录也失败:
mariadb -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
然后创建默认管理员用户与您的 MacOS 帐户 用户名 相同的名称,例如约翰斯密特。
要以 root 身份登录并设置 root 密码,请发出(使用 您的 用户名):
mariadb -u johnsmit
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 10.4.11-MariaDB Homebrew
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'ROOT-PASSWORD';
Query OK, 0 rows affected (0.006 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.002 sec)
MariaDB [(none)]> exit
Bye
所以你在 localhost 上从 mysql 更改 root 密码。
奖励:要更改当前或其他用户通行证,您可以使用mysqladmin 命令:
$(brew --prefix mariadb)/bin/mysqladmin -u arunas password 'newsecret'
但是由于某种原因这不会影响本地主机,但应该适用于应用程序登录。
或者使用本地 MySQL 更改用户密码 SQL,它明确指定主机,在我的例子中是用户的 'localhost' 帐户:
mariadb -u arunas
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.5.9-MariaDB Homebrew
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> ALTER USER 'arunas'@'localhost' IDENTIFIED BY 'newsecret';
Query OK, 0 rows affected (0.006 sec)
MariaDB [(none)]> exit
Bye
现在让我们尝试无密码登录:
mariadb -u arunas
ERROR 1045 (28000): Access denied for user 'arunas'@'localhost' (using password: NO)
您看到登录失败,因此现在我们需要指定密码的需要:
mariadb -u arunas -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.5.9-MariaDB Homebrew
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> exit
Bye
祝您使用愉快!