在MacOS Mojave上通过自制程序(即brew install mysql@5.7
)安装mysql时,似乎成功安装会显示以下说明:
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
的密码?
答案 0 :(得分:2)
似乎通过--password
标志使用“空字符串”密码可以解决此问题:
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
答案 1 :(得分:0)
在安装新的brew mysql之后:
1)确保mysql正在运行:brew服务启动mysql
2)更改mysql密码:mysqladmin -uroot --password =“”密码'NEWPASSWORD'
3)安全的mysql:mysql_secure_installation(使用新密码)
答案 2 :(得分:0)
我认为所有在安装后运行mysql_secure_installation
命令的人都会遇到此麻烦。
我们需要附加用户名和密码参数,以便对此进行思考:
mysql_secure_installation -u root --password=""