mysql - 在 OS X 上设置 MySQL root 用户密码

标签 mysql macos passwords

我刚刚在 Mac OS X 上安装了 MySQL。下一步是设置 root 用户密码,所以接下来我这样做了:

  1. 启动终端应用程序以访问 Unix 命令行。

  2. 在 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/

相关文章:

mysql - 从最高到最低分组

php - MySQL - 无法将时间格式转换为秒

mysql - 将 blob 字符串保存到 mysql

python - py-appscript 和事件

macos - 汇编程序错误 : Mach-O 64 bit does not support absolute 32 bit addresses

linux - popen密码更改linux

python - 使用Popen执行scp,无需输入密码

python - 如何使用python在mysql中插入python dict的键和值

macos - 在 NSPersistentDocument 上启用核心数据的自动轻量级迁移

sql - PostgreSQL:为什么我可以连接到具有设置密码的用户而无需提供密码?