MySQL 密码问题(Mac OS X Lion)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8541115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 22:04:10  来源:igfitidea点击:

MySQL password issues (mac OS X Lion)

mysqlosx-lion

提问by user1072337

I am trying to set the root password for MySQL in the terminal in Mac OS X Lion, and I am having issues. Every time I use the line:

我正在尝试在 Mac OS X Lion 的终端中为 MySQL 设置 root 密码,但我遇到了问题。每次我使用这条线时:

/usr/local/mysql/bin/mysqladmin -u root password ******  (where ****** is the password I want to set)

I receive the error:

我收到错误:

/usr/local/mysql/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'

I have not set a password previously, so I do not know why I am receiving this error.

我之前没有设置密码,所以我不知道为什么我会收到这个错误。

回答by minhas23

Here is the procedure to reset password of root user.

下面是重置root用户密码的过程。

1) Stop mysql (Kill mysql process or run following command)

1)停止mysql(杀死mysql进程或运行以下命令)

sudo /usr/local/mysql/support-files/mysql.server stop

2) Start it in safe mode

2)以安全模式启动

sudo mysqld_safe --skip-grant-tables

3) Open another terminal and run the following command (Keep last terminal open)

3)打开另一个终端并运行以下命令(保持最后一个终端打开)

mysql -u root

4) Run the following command with suitable new password on the mysql console

4)在mysql控制台上使用合适的新密码运行以下命令

For MySQL 5.7+:

对于 MySQL 5.7+:

mysql > UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';

For earlier versions:

对于早期版本:

mysql > UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';

5) mysql > FLUSH PRIVILEGES;

5) mysql > FLUSH PRIVILEGES;

6) Quit from both terminals and open new terminal and connect to mysql with root user and new password

6)退出两个终端并打开新终端并使用root用户和新密码连接到mysql

mysql -uroot -p

回答by Huge

Type:/usr/local/mysql/bin/mysqladmin -u root -p password

类型:/usr/local/mysql/bin/mysqladmin -u root -p password

When it asks for a password, not not enter anything, just hit enter. It will then ask you to enter new password, then confirm. Finished.

当它要求输入密码时,不要输入任何内容,只需按 Enter。然后它会要求您输入新密码,然后确认。完成的。

回答by Kashif Khan

for creating password first time use

用于创建密码第一次使用

mysqladmin -u root password NEWPASSWORD

updating old password use

更新旧密码使用

mysqladmin -u root -p'oldpassword' password newpass

Source = http://www.cyberciti.biz/faq/mysql-change-root-password/

来源 = http://www.cyberciti.biz/faq/mysql-change-root-password/

回答by Ricardo Cruz

I'm on Yosemite, but on Maverick has the same problem. - Fix the 2002 socket error first if you haven't done

我在优胜美地,但在 Maverick 上也有同样的问题。- 如果您还没有完成,请先修复 2002 套接字错误

sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

An then try

然后尝试

sudo /usr/local/mysql/bin/mysqladmin -u root -p password

回答by daemonofchaos

That isn't how you set the password. That is how you login to mysql.

那不是您设置密码的方式。这就是您登录mysql的方式。

If you don't have a password set, you login using:

如果您没有设置密码,请使用以下方式登录:

mysql -u root

and that will get you to the MySQL command line.

这将使您进入 MySQL 命令行。

Instead of doing that just use the following to change the password.

而不是这样做,只需使用以下内容来更改密码。

mysqladmin -u root password NEWPASSWORD

回答by Donald Derek

cd /usr/local/mysql/bin

./mysqladmin -u root password root

回答by user8249200

To set your root password after installing:

安装后设置root密码:

  1. Ensure MySQL is not running, stop it if you ran it.
  2. On a Terminal do sudo mysqld_safe --skip-grant-tablesto run MySQL bypassing the authentication.
  3. Inside mysql do FLUSH PRIVILEGES;
  4. Then reset by SET PASSWORD FOR root@'localhost' = PASSWORD('password');where 'password' is your chosen password.
  5. FLUSH PRIVILEGES;one more time
  1. 确保 MySQL 没有运行,如果您运行它,请停止它。
  2. 在终端sudo mysqld_safe --skip-grant-tables上运行 MySQL 绕过身份验证。
  3. 在mysql里面做 FLUSH PRIVILEGES;
  4. 然后通过SET PASSWORD FOR root@'localhost' = PASSWORD('password');“密码”是您选择的密码进行重置。
  5. FLUSH PRIVILEGES;再一次

回答by Max

This fix it for me: After this is going to ask you for your Super User password and then for the new password.

这对我来说是修复它:在这之后会询问您的超级用户密码,然后是新密码。

sudo /usr/local/mysql/bin/mysqladmin -u root -p password

sudo /usr/local/mysql/bin/mysqladmin -u root -p 密码

回答by Devrim

You want to reset or set a new root password?

您想重置或设置新的 root 密码吗?

Steps for MySQL 5.7.5 and earlier:

MySQL 5.7.5 及更早版本的步骤:

Open a Terminal Window:

打开终端窗口:

  1. Stop mysql server if it is running:

    sudo /usr/local/mysql/support-files/mysql.server stop

  2. Restart it with the --skip-grant-tablesoption:

    sudo mysqld_safe --skip-grant-tables

  1. 如果 mysql 服务器正在运行,请停止它:

    sudo /usr/local/mysql/support-files/mysql.server stop

  2. 使用以下--skip-grant-tables选项重新启动它:

    sudo mysqld_safe --skip-grant-tables

Open another Terminal Window:

打开另一个终端窗口:

  1. Type: mysql -u root

  2. Reset root password (i.e. for localhost)

    UPDATE mysql.user SET authentication_string = PASSWORD(‘MyNewPass'), password_expired = 'N' WHERE User = 'root' AND Host = 'localhost'; FLUSH PRIVILEGES;

  1. 类型: mysql -u root

  2. 重置 root 密码(即本地主机)

    UPDATE mysql.user SET authentication_string = PASSWORD(‘MyNewPass'), password_expired = 'N' WHERE User = 'root' AND Host = 'localhost'; FLUSH PRIVILEGES;

Now your password for root@localhost is MyNewPass. You can change it:

现在 root@localhost 的密码是MyNewPass。你可以改变它:

  1. Close all Terminal Windows. Open a new Terminal Window and type:

    mysqladmin -u root -p'MyNewPass' password '123456'

    Now your root password is 123456

    You should see below warning message, you can ignore it if you are changing your root@localhost password:

    mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

  2. Check if your root password is successfully changed:

    mysql -u root -p'123456' -e 'show databases;'

    Output:

    mysql: [Warning] Using a password on the command line interface can be insecure.

    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mysql |
    | performance_schema |
    | sys |
    +--------------------+

  1. 关闭所有终端窗口。打开一个新的终端窗口并输入:

    mysqladmin -u root -p'MyNewPass' password '123456'

    现在你的 root 密码是123456

    您应该会看到以下警告消息,如果您正在更改 root@localhost 密码,则可以忽略它:

    mysqladmin: [警告] 在命令行界面上使用密码可能不安全。警告:由于密码将以明文形式发送到服务器,请使用 ssl 连接以确保密码安全。

  2. 检查您的root密码是否成功更改:

    mysql -u root -p'123456' -e 'show databases;'

    输出:

    mysql:[警告] 在命令行界面上使用密码可能不安全。

    +--------------------+
    | 数据库 |
    +--------------------+
    | information_schema |
    | mysql |
    | 性能模式|
    | 系统 |
    +--------------------+

回答by Elango Dhanasekaran

This is working on macOS Sierra

这适用于 macOS Sierra

step 1: open terminal

第一步:打开终端

step 2: paste the following command

第二步:粘贴以下命令

     sudo /usr/local/mysql/support-files/mysql.server restart

Your terminal should show this :

你的终端应该显示这个:

     Users-MacBook-Air:~ usr$ sudo /usr/local/mysql/support-files/mysql.server restart

Password: ERROR! MySQL server PID file could not be found!

密码:错误!找不到 MySQL 服务器 PID 文件!

Starting MySQL .. SUCCESS!

启动 MySQL .. 成功!

Step 3: Make sure SQL server is running

第 3 步:确保 SQL 服务器正在运行

Step 4: Open the MYSQL working and click the local instance

第四步:打开MYSQLworking,点击本地实例

Step 5: type old password and new password

第五步:输入旧密码和新密码