我刚刚在 Mac OS X 上安装了 MySQL。下一步是设置 root 用户密码,所以接下来我这样做了:
启动终端应用程序以访问 Unix 命令行。
在 Unix 提示符下我执行了以下命令:
cd /usr/local/mysql/bin ./mysqladmin -u root password 'password'
但是,当我执行命令时
./mysql -u root
,这就是答案:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 224
Server version: 5.5.13 MySQL Community Server (GPL)
Copyright (c) 2000, 2010, 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.
mysql>
我不需要任何密码就可以进入mysql
命令行!
这是为什么?
最佳答案
登录 MySQL 终端时尝试命令 FLUSH PRIVILEGES
。如果这不起作用,请在 MySQL 终端中尝试以下命令集
mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET password=PASSWORD("NEWPASSWORD") WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
用您想要的任何密码更改 NEWPASSWORD。应该已经全部设置完毕!
更新:从 MySQL 5.7 开始,password
字段已重命名为 authentication_string
。更改密码时,使用以下查询来更改密码。所有其他命令保持不变:
mysql> UPDATE user SET authentication_string=PASSWORD("NEWPASSWORD") WHERE User='root';
对于 MySQL 8.0+ 不要使用
mysql> UPDATE mysql.user SET authentication_string='password' WHERE User='root';
因为它会覆盖 authentication_string
(它应该是哈希值而不是纯文本),所以请使用:
mysql> `ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';`
关于mysql - 在 OS X 上设置 MySQL root 用户密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41484072/