问题描述
我刚刚在 Mac OS X 上安装了 MySQL.下一步是设置 root 用户密码,所以我接下来做了:
I just installed MySQL on Mac OS X. The next step was setting the root user password, so I did this next:
- 启动终端应用以访问 Unix 命令行.
在 Unix 提示符下我执行了以下命令:
- Launch the terminal app to access the Unix command line.
Under the Unix prompt I executed these commands:
$ 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
命令行!
I can get into the mysql
command line without any password!
这是为什么?
推荐答案
在登录 MySQL 终端时尝试命令 FLUSH PRIVILEGES
.如果这不起作用,请在 MySQL 终端中尝试以下命令集
Try the command FLUSH PRIVILEGES
when you log into the MySQL terminal. If that doesn't work, try the following set of commands while in the MySQL terminal
$ mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET password=PASSWORD("NEWPASSWORD") WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
使用您想要的任何密码更改 NEWPASSWORD.应该都准备好了!
Change out NEWPASSWORD with whatever password you want. Should be all set!
更新:从 MySQL 5.7 开始,password
字段已重命名为 authentication_string
.更改密码时,请使用以下查询更改密码.所有其他命令保持不变:
Update: As of MySQL 5.7, the password
field has been renamed authentication_string
. When changing the password, use the following query to change the password. All other commands remain the same:
mysql> UPDATE user SET authentication_string=PASSWORD("NEWPASSWORD") WHERE User='root';
更新:在 8.0.15(可能已经在该版本之前),PASSWORD() 函数不起作用,如下面的评论中所述.你必须使用:
Update: On 8.0.15 (maybe already before that version) the PASSWORD() function does not work, as mentioned in the comments below. You have to use:
UPDATE mysql.user SET authentication_string='password' WHERE User='root';
这篇关于在 OS X 上设置 MySQL root 用户密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!