MySQL - 错误 1045 - 访问被拒绝

发布于 2024-07-12 08:07:10 字数 515 浏览 17 评论 0原文

在某种程度上,当我尝试通过命令行访问 MySQL 时,我设法收到此错误:

[root@localhost ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

我尝试使用此 HowTo 重置密码,但没有任何运气。

我已经卸载了 mysql completley 并重新安装,但仍然被要求输入密码。 我不知道为什么会这样!

有人可以帮我获得 MySQL 的默认安装吗?

环境

Fedora Core 10,完全根访问权限,安装了 Apache 和 PHP

感谢您的帮助!

编辑

对于所有那些想要节省自己几个小时“咳血”的人 - 当您卸载 MySQl 时完全删除留下的所有内容。 如果您不这样做,它将永远不会是全新安装。

In some way I have managed to get this error when I try to access into MySQL via the command line:

[root@localhost ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

I have tried resetting the password without any luck using this HowTo.

I have uninstalled mysql completley and reinstalled but I still get asked for a password. I have no idea why this is the case!

Can someone please help me get a default install of MySQL.

Environment

Fedora Core 10, Full Root Access, Apache and PHP installed

Thank you for any help!!

EDIT

To all those that would like to save themselves a few hours of "blood coughing" - when you uninstall MySQl completely delete everything that is left behind. If you don't do this, it will never be a FRESH install.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

美男兮 2024-07-19 08:07:10

如果您实际上已经设置了 root 密码,并且刚刚丢失/忘记了它:

  1. 停止 MySQL
  2. 使用skip-grant-tables 选项手动重新启动它:mysqld_safe --skip-grant-tables

  3. 现在,打开一个新的终端窗口并运行MySQL客户端:mysql -u root

  4. 使用以下 MySQL 命令手动重置 root 密码:<代码>更新 mysql.user SET 密码=PASSWORD('密码') WHERE User='root';
    如果您使用 MySQL 5.7(在终端中使用 mysql --version 检查),则命令为:

    UPDATE mysql.user SETauthentication_string=PASSWORD('password') WHERE User='root'; 
      
  5. 使用此 MySQL 命令刷新权限:FLUSH PRIVILEGES;

来自 http:// /www.tech-faq.com/reset-mysql-password.shtml

(也许这不是你所需要的,Abs,但我认为这对于将来遇到这个问题的人来说可能很有用)

If you actually have set a root password and you've just lost/forgotten it:

  1. Stop MySQL
  2. Restart it manually with the skip-grant-tables option: mysqld_safe --skip-grant-tables

  3. Now, open a new terminal window and run the MySQL client: mysql -u root

  4. Reset the root password manually with this MySQL command: UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
    If you are using MySQL 5.7 (check using mysql --version in the Terminal) then the command is:

    UPDATE mysql.user SET authentication_string=PASSWORD('password')  WHERE  User='root';
    
  5. Flush the privileges with this MySQL command: FLUSH PRIVILEGES;

From http://www.tech-faq.com/reset-mysql-password.shtml

(Maybe this isn't what you need, Abs, but I figure it could be useful for people stumbling across this question in the future)

相对绾红妆 2024-07-19 08:07:10

尝试不使用任何密码进行连接:

mysql -u root

我相信 root 帐户的初始默认设置是没有密码的(显然应该尽快更改)。

Try connecting without any password:

mysql -u root

I believe the initial default is no password for the root account (which should obviously be changed as soon as possible).

一念一轮回 2024-07-19 08:07:10

使用此命令检查可能的输出

mysql> select user,host,password from mysql.user;

输出

mysql> select user,host,password from mysql.user;
+-------+-----------------------+-------------------------------------------+
| user  | host                  | password                                  |
+-------+-----------------------+-------------------------------------------+
| root  | localhost             | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| root  | localhost.localdomain | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| root  | 127.0.0.1             | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| admin | localhost             | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| admin | %                     |                                           |
+-------+-----------------------+-------------------------------------------+
5 rows in set (0.00 sec)
  1. 在此用户中,尽管您已授予权限,但将不允许管理员从其他主机登录。 原因是用户admin没有任何密码来识别。
  2. 使用GRANT命令再次授予用户admin密码

    mysql>   将 *.* 上的所有权限授予由“密码”标识的“admin”@“%” 
      

输出将与他的类似,

mysql> select user,host,password from mysql.user;

+-------+-----------------------+-------------------------------------------+
| user  | host                  | password                                  |
+-------+-----------------------+-------------------------------------------+
| root  | localhost             | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| root  | localhost.localdomain | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| root  | 127.0.0.1             | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| admin | localhost             | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| admin | %                     | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
+-------+-----------------------+-------------------------------------------+
5 rows in set (0.00 sec)

然后检查 GRANT LIST ,如果需要允许所需的用户(例如用户“admin”)登录,则 然后使用一次GRANT 命令并执行该命令。

现在应该允许用户登录。

use this command to check the possible output

mysql> select user,host,password from mysql.user;

output

mysql> select user,host,password from mysql.user;
+-------+-----------------------+-------------------------------------------+
| user  | host                  | password                                  |
+-------+-----------------------+-------------------------------------------+
| root  | localhost             | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| root  | localhost.localdomain | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| root  | 127.0.0.1             | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| admin | localhost             | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| admin | %                     |                                           |
+-------+-----------------------+-------------------------------------------+
5 rows in set (0.00 sec)
  1. In this user admin will not be allowed to login from another host though you have granted permission. the reason is that user admin is not identified by any password.
  2. Grant the user admin with password using GRANT command once again

    mysql> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED by 'password'
    

then check the GRANT LIST the out put will be like his

mysql> select user,host,password from mysql.user;

+-------+-----------------------+-------------------------------------------+
| user  | host                  | password                                  |
+-------+-----------------------+-------------------------------------------+
| root  | localhost             | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| root  | localhost.localdomain | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| root  | 127.0.0.1             | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| admin | localhost             | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| admin | %                     | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
+-------+-----------------------+-------------------------------------------+
5 rows in set (0.00 sec)

if the desired user for example user 'admin' is need to be allowed login then use once GRANT command and execute the command.

Now the user should be allowed to login.

天赋异禀 2024-07-19 08:07:10

当前 root 密码必须为空。
然后在“新 root 密码”下输入您的密码并确认。

The current root password must be empty.
Then under "new root password" enter your password and confirm.

琉璃繁缕 2024-07-19 08:07:10
  1. 进入mysql控制台
  2. 输入use mysql;
  3. UPDATE mysql.user SET 密码= PASSWORD ('') WHERE User='root'
    同花顺特权;
    出口
    PASSWORD ('') 必须为空 然后
  4. 转到 wamp/apps/phpmyadmin../config.inc.php
  5. 找到 $cfg ['Servers']['$I']['password']='root';
  6. 将 ['密码'] 替换为 ['您的旧密码']
  7. 保存文件
  8. 重新启动所有服务并转到 localhost/phpmyadmin
  1. Go to mysql console
  2. Enter use mysql;
  3. UPDATE mysql.user SET Password= PASSWORD ('') WHERE User='root'
    FLUSH PRIVILEGES;
    exit
    PASSWORD ('') is must empty
  4. Then go to wamp/apps/phpmyadmin../config.inc.php
  5. Find $cfg ['Servers']['$I']['password']='root';
  6. Replace the ['password'] with ['your old password']
  7. Save the file
  8. Restart the all services and goto localhost/phpmyadmin
伴我心暖 2024-07-19 08:07:10

我遇到了同样的错误,但这是因为 password_expired 设置为 Y。 您可以按照与当前接受的答案相同的方法来解决该问题,但改为执行 MySQL 查询:

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

I had the same error, but it was because password_expired was set to Y. You can fix that issue by following the same approach as the currently accepted answer, but instead executing the MySQL query:

UPDATE mysql.user SET password_expired = 'N' WHERE User='root';
酷到爆炸 2024-07-19 08:07:10

我无法连接到 MySql 管理员。 我通过创建另一个用户并分配所有权限来修复它。

我用那个新用户登录并且它起作用了。

I could not connect to MySql Administrator. I fixed it by creating another user and assigning all the permissions.

I logged in with that new user and it worked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文