68

我已经擦除并安装了OSX 10.11 El Capitan,我一直在按照本教程在新的 OS X上MySQL启动和运行。第一步是下载MySQL For Mac OS X 10.9(x86,64 位),DMG 存档(适用于 10.11 ,他们在教程中推荐)。当我完成安装 MySQL 时,我收到消息说:

2015-10-25T02:10:54.549219Z 1 [Note] A temporary password is generated for root@localhost: R>gFySuiu23U

If you lose this password, please consult the section How to Reset the Root Password in the MySQL reference manual.

很奇怪,我从来没有见过这样的消息。之后,我通过 Preference Pane 启动 MySQL,然后/usr/local/mysql/bin/mysql -v在终端上使用命令进行下一步。我收到一条错误消息:

ERROR 1045 (28000): Access denied for user 'cheetah'@'localhost' (using password: NO)

我还尝试通过Sequel Pro使用 root 作为用户名和空白密码来访问数据库,我收到拒绝访问的消息说:

Unable to connect to host 127.0.0.1 because access was denied.

Double-check your username and password and ensure that access from your current location is permitted.

MySQL said: Access denied for user 'root'@'localhost' (using password: NO)

好的,我也再次尝试使用 root 作为用户名,但使用“R>gFySuiu23U”作为密码(从 MySQL 生成)。我收到连接失败消息说:

Unable to connect to host 127.0.0.1, or the request timed out.

Be sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently 10 seconds).

MySQL said: Your password has expired. To log in you must change it using a client that supports expired passwords.

我该如何解决这个问题?我记得 MySQL 从来没有像这样自动生成临时密码,不是吗?

4

17 回答 17

106

尝试这个:

mysql -u root -h 127.0.0.1 -p
Enter password: (enter the random password here)

参考:https ://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization-mysqld.html

在此之后,您可以使用重置密码 ALTER USER 'root'@'localhost' IDENTIFIED BY 'new-password';

于 2015-10-25T17:04:59.500 回答
41

这就是在运行 MySql v5.7(从 .dmg 安装)的 OS X Yosemite 上对我有用的方法。

cd /usr/local/mysql/bin
./mysql -u root -p --connect-expired-password

(输入安装程序生成的临时密码。)

这会让您进入沙盒模式mysql>提示。然后使用SET PASSWORD设置所需的 root 密码:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('mySuperSecretPassword');
于 2016-03-01T17:35:05.153 回答
37

Now that the password MySQL had generated is expired, the problem is reduced to getting this password to work again (1) or generate a new one (2). This can be accomplished by running MySQL with the skip-grant-tables option which would make it ignore the access rights:

  1. Stop your MySQL server.

  2. Add the below at the end of the [mysqld] section of my.cnf file and save it.

    skip-grant-tables

  3. Start MySQL server.

  4. In terminal, type

    mysql -u root -p

to get into MySQL command prompt.

  1. In the command prompt, type

    USE mysql;

to get into the mysql database where it keeps database users.

  1. Type

    UPDATE user SET password_expired = 'N' WHERE User = 'root';

to let MySQL know the password is not expired (1) or

UPDATE user SET authentication_string = PASSWORD('YourNewPassword'), password_expired = 'N' WHERE User = 'root';

to assign a new password YourNewPassword to root (2).

于 2015-11-06T09:25:04.037 回答
16

在 OSX 10.11 El Capitan 和 MySQL 5.7.X 下执行这些步骤应该可以解决问题。

考虑到你已经安装了 MySQL ..

打开终端窗口并输入:

  1. sudo /usr/local/mysql/support-files/mysql.server 停止
  2. sudo mysqld_safe --skip-grant-tables

由于步骤 2 中触发的命令将处于运行状态,因此您需要打开另一个终端窗口,然后键入:

  1. mysql -u 根目录 -p
  2. UPDATE mysql.user SET password_expired='N', authentication_string=PASSWORD('') WHERE User='root';
  3. 退出;
  4. sudo /usr/local/mysql/support-files/mysql.server 重启

重要提示:在第 2 步中,您必须替换您的密码。

希望它会适合你。

于 2016-07-28T17:38:06.303 回答
5

MySQL 密码已过期

重置密码会暂时解决问题,但是,从 MySQL 5.7.4 到 5.7.10(我认为是为了鼓励更好的安全性)该default_password_lifetime变量的默认值为 360(大约一年)。对于这些版本,如果您不更改此变量(或单个用户帐户),所有用户密码都会在 360 天后过期。

通常,您可能会从脚本中收到以下消息:“您的密码已过期。要登录,您必须使用支持过期密码的客户端进行更改。”

因此,为防止密码自动过期,请以 root ( mysql -u root -p) 身份登录,然后,对于自动连接到服务器的客户端(例如脚本)。更改这些客户端的密码过期设置:

ALTER USER 'script'@'localhost' PASSWORD EXPIRE NEVER;

或者您可以为所有用户禁用自动密码过期:

SET GLOBAL default_password_lifetime = 0;

链接:

MySQL:密码过期和沙盒模式
MySQL:密码过期策略
MySQL Server 5.7 中的密码过期策略

于 2017-01-09T16:01:04.687 回答
4

我正在运行 macOS Sierra(10.12.3) 并安装了 mysql-5.7.17-macos10.12-x86_64.dmg。

@lesley 的答案对我有用,除了我需要添加./以确保我在当前工作目录中调用 mysql 二进制文件。这是安装上述软件包的位置。

如果您cd运行/usr/local/mysql/bin并运行mysql -u root -p --connect-expired-password,您可能会收到以下错误。

mysql: unknown option '--connect-expired-password'

我做到了。因为简单地运行mysql而不提供路径,称为以前安装的 MariaDB 客户端版本。

因此,为了确保您正在执行正确的二进制文件,您可以

提供绝对路径

/usr/local/mysql/bin/mysql -u root -p --connect-expired-password

或更改目录后的相对路径

cd /usr/local/mysql/bin
./mysql -u root -p --connect-expired-password

两种方式都应该有效。连接到客户端后,说明与上面来自@lesley 的说明相同。

输入安装程序生成的临时密码并设置新密码。

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourNewPassword'); 
于 2016-12-30T06:29:29.540 回答
2

我遇到了同样的问题。我按照https://www.ntu.edu.sg/home/ehchua/programming/sql/MySQL_HowTo.html中的安装过程指南下载了 DMG 存档并在我的 MAC OS X 10.12.2 上安装了 MySQL。

最后在新终端上执行以下命令。

cd /usr/local/mysql/bin

./mysql -u root -p --connect-expired-password

有效。

于 2017-05-25T10:57:07.687 回答
1

这个特别的对我有用:

如此链接中所述:https ://www.variphy.com/kb/mac-os-x-reset-mysql-root-password

执行除执行之外的所有步骤

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

执行

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

然后执行 FLUSH PRIVILEGES;

于 2017-12-28T23:53:29.140 回答
1

对于 Mysql 5.7,我使用

shell $ > sudo grep '临时密码' /var/log/mysqld.log

于 2016-04-25T10:21:21.787 回答
1

答案 7 对我有用:El capitanMySQL从 dmg 和自动生成的密码安装,但在进入 Obvious 之前一定cd要这样做/usr/local/bin/mysql./mysql -root -p 但我不是第一次。

现在找到我所有的数据库和表在哪里以及如何链接它们。

于 2016-01-09T01:50:48.650 回答
0

首次通过下载包手动安装 MySQL 会生成 root 的默认密码。复制并保存。如果在连续重新安装时未以某种方式完成,则不会显示该密码。

因此,您无法登录到 root。请执行下列操作 :

  1. 从系统中查找mysql相关条目 sudo find / -name mysql
  2. 通过执行删除所有mysql相关条目rm -rf <mysql_entries_above>
  3. 下载最新的 mysql-server 并安装它。
  4. 系统将提示您输入需要复制的默认密码。
  5. mysql_secure_installation在要求 root 时运行并粘贴该密码。
  6. 随后按照步骤操作并在提示时更改管理员密码。
于 2018-01-24T11:37:44.820 回答
0

但是在Mysql80-Server中,比5.7复杂。在 MySQL80 中,不允许您在“跳过授权表”状态下的 my.cnf 中的配置期间更新或更改密码。所以你需要3个大步骤来做

I) 将my.cnf更改为skip-grant-table

II) 使用空白密码登录 MySQL 并将表更新为空白密码

III)重启mysql并使用空白密码登录并更新为新密码

步骤:(无论如何,您忘记了 root 密码,安装时生成的临时密码不起作用等,请按照以下步骤操作)在我的情况下,在 FreeBSD 12.2 上

  1. 停止你的mysql服务器

    /usr/local/etc/rc.d/mysql-server stop
    
  2. 再次检查是否真的停止(以防更严重的问题)

    /usr/local/etc/rc.d/mysql-server status
    
    mysql is not running.
    
  3. 找到您的 my.cnf 文件并将“ skip-grant-tables ”添加到其中。(通常在[Mysqldump]头部之前)

  4. 重启mysql

    /usr/local/etc/rc.d/mysql-server start
    
  5. 登录到mysql

    mysql -u root -p
    

    当它要求输入密码时,只需按 enter 即可登录 mysql

  6. 选择要使用的数据库

    use mysql
    
  7. 看表用户

    select user, authentication_string,password_expired from user;
    
  8. 更新为空密码

    UPDATE user SET authentication_string = '', password_expired='N' WHERE User = 'root'; 
    
  9. 退出 mysql 并使 mysql 停止

  10. 转到文件 my.cnf 然后将“ skip-grant-tables ”从文件中取出。

  11. 再次使用“mysql -u root -p”重新启动mysql 输入空白密码

  12. 然后

ALTER USER 'root'@'localhost'   IDENTIFIED WITH
    caching_sha2_password BY 'YourNewPassword';
  1. 退出 mysql 并使 mysql 停止
  2. 再次重新启动mysql,然后您将使用新密码登录
于 2021-09-24T15:48:53.173 回答
0

我安装了 view brew,在我注意到这个警告之前,我收到了同样的错误消息:

我们在没有 root 密码的情况下安装了您的 MySQL 数据库。为了保护它运行:mysql_secure_installation

连接运行:mysql -uroot

现在启动 mysql 并在登录时重新启动: brew services start mysql

或者,如果您不想要/不需要后台服务,您可以运行:mysql.server start

于 2017-01-31T23:47:06.147 回答
0

解决此问题的另一种方法是改用旧版本的 MySQL。

我已经卸载MySQL version 5.7.9了 Mac OS X 10.9 (x86, 64-bit) DMG Archive,然后安装了旧版本MySQL version 5.6.7的 Mac OS X 10.9 (x86, 64-bit) DMG Archive。这个问题解决了。在完成安装此旧版本之前给定的自动生成密码已经消失,我最终可以使用 root 作为用户名和空白密码访问数据库。一切都像魅力一样运作!

于 2015-10-26T16:48:56.580 回答
0

我通过运行 'mysql -u root -p --connect-expired-password' Then input the expired auto-gen password from mysql 解决了这个问题。终于进去了。选择了mysql db, 'use mysql' 然后更新了用户'root'pw 'ALTER USER 'root'@'localhost' IDENTIFIED BY 'your new password'

于 2017-10-05T00:08:42.700 回答
0

重新启动 Mysql 服务器对我有用。

于 2020-03-24T12:28:35.007 回答
-1

当您之前安装了 mysql 时,可能会发生这种情况。试试你为最后一个版本的mysql设置的密码。这确实对我有用。

于 2018-10-24T14:38:40.280 回答