我刚刚在 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/6474775/