macos mojave-brew安装mysql@5.7 -拒绝访问用户“root”@“localhost”

jv4diomz  于 2021-06-18  发布在  Mysql
关注(0)|答案(3)|浏览(542)

通过自制程序安装mysql时(即。 brew install mysql@5.7 )在macos mojave上,看似成功的安装会打印以下说明:

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 -uroot ,或 mysql_secure_installation 运行时,出现以下错误:

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

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

vojdkbi0

vojdkbi01#

安装新的brew mysql后:
1) 确保mysql正在运行:brew服务启动mysql
2) 更改mysql密码:mysqladmin-uroot--password=“”password'新密码'
3) secure mysql:mysql\u secure\u安装(使用新密码)

nr9pn0ug

nr9pn0ug2#

似乎通过 --password flag解决了这个问题:

mysql -uroot --password=""

或者,您可以手动启动 mysqld--skip-grant-tables :

$ 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
4ktjp1zp

4ktjp1zp3#

我想所有的人 mysql_secure_installation 安装后的命令会遇到这种麻烦。
我们需要附加用户名和密码参数以获得以下信息:

mysql_secure_installation -u root --password=""

相关问题