Linux MySQL - 错误 1045 - 访问被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/489119/
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-03 16:55:56  来源:igfitidea点击:

MySQL - ERROR 1045 - Access denied

mysqllinuxpasswordsmysql-error-1045

提问by Abs

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

以某种方式,当我尝试通过命令行访问 MySQL 时,我设法得到了这个错误:

[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.

我尝试使用此 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!

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

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

有人可以帮助我获得 MySQL 的默认安装。

Environment

环境

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

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

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.

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

采纳答案by David Z

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

如果您确实设置了 root 密码并且您刚刚丢失/忘记了它:

  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;

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

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

  4. 使用此 MySQL 命令手动重置 root 密码:UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';如果您使用的是 MySQL 5.7(在终端中使用 mysql --version 检查),则命令为:

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

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

来自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)

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

回答by Chad Birch

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).

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

回答by princetailor

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

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

回答by user4713247

  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
  1. 转到 mysql 控制台
  2. 输入使用mysql;
  3. 更新 mysql.user SET Password= PASSWORD ('') WHERE User='root' FLUSH PRIVILEGES; 退出密码 ('') 必须为空
  4. 然后去 wamp/apps/phpmyadmin../config.inc.php
  5. 找到 $cfg ['Servers']['$I']['password']='root';
  6. 将 ['password'] 替换为 ['your old password']
  7. 保存文件
  8. 重新启动所有服务并转到 localhost/phpmyadmin

回答by vigremrajesh

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'
    
  1. 在此用户中,尽管您已授予权限,但不允许从其他主机登录。原因是用户 admin 没有被任何密码识别。
  2. 再次使用 GRANT 命令授予用户 admin 密码

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

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

然后检查 GRANT LIST 输出将像他的一样

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.

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

Now the user should be allowed to login.

现在应该允许用户登录。

回答by Mysql user

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

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

I logged in with that new user and it worked.

我用那个新用户登录,它工作正常。

回答by Brandon

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

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

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