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

Setting the MySQL root user password on OS X(在 OS X 上设置 MySQL root 用户密码)
本文介绍了在 OS X 上设置 MySQL root 用户密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我刚刚在 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:

  1. 启动终端应用以访问 Unix 命令行.
  2. 在 Unix 提示符下我执行了以下命令:

  1. Launch the terminal app to access the Unix command line.
  2. 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 用户密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Can#39;t Create Entity Data Model - using MySql and EF6(无法创建实体数据模型 - 使用 MySql 和 EF6)
MySQL select with CONCAT condition(MySQL选择与CONCAT条件)
Capitalize first letter of each word, in existing table(将现有表格中每个单词的首字母大写)
How to retrieve SQL result column value using column name in Python?(如何在 Python 中使用列名检索 SQL 结果列值?)
Update row with data from another row in the same table(使用同一表中另一行的数据更新行)
Exporting results of a Mysql query to excel?(将 Mysql 查询的结果导出到 excel?)