MacOS Mojave - brew安装mysql@5.7 - 用户'root'@'localhost'访问被拒绝

4

在 MacOS Mojave 上通过 Homebrew 安装 MySQL(例如 brew install mysql@5.7)时,看似安装成功,但会打印以下指令:

We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

当运行mysql -urootmysql_secure_installation时,我会收到以下错误提示:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

如何登录mysql来更改root用户的密码?

3个回答

4

看起来通过--password标志使用“空字符串”密码可以解决这个问题:

mysql -uroot --password=""

或者,您可以手动使用--skip-grant-tables选项启动mysqld

$ mysql.server --skip-grant-tables
$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24 Homebrew

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

$ 

最后使用以下命令更改密码:

mysqladmin -uroot --password="" password NEW_PASSWORD

我不确定默认的mysql密码是如何设置为“”空字符串的,但如果其他人投票支持此帖子(证明可重现性),我将向homebrew发起Pull Request尝试修复此问题,或者至少更新homebrew的“注意事项”以包括“--password =''”。 - The Aelfinn

0

我认为所有在安装后运行mysql_secure_installation命令的人都会遇到这个问题。

我们需要添加用户名和密码参数来解决这个问题:

mysql_secure_installation -u root --password=""

0

在安装新的brew mysql之后:

1)确保mysql正在运行:brew services start mysql

2)更改mysql密码:mysqladmin -uroot --password="" password 'NEWPASSWORD'

3)保护mysql:mysql_secure_installation(使用新密码)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接