MySQL 错误 1045 (28000): 用户 'root'@'localhost' 访问被拒绝(使用密码:NO)

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

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

mysql

提问by Marcos

I lost the access onto MySQL v. 5.6.14. I had access and suddenly I lost it.

我失去了对 MySQL v. 5.6.14 的访问权限。我可以访问,但突然间我失去了它。

Looking for notes I found out the url below. I did the steps, but not success. http://dev.mysql.com/doc/refman/5.5/en/resetting-permissions.html

寻找笔记我发现了下面的网址。我做了这些步骤,但没有成功。 http://dev.mysql.com/doc/refman/5.5/en/resetting-permissions.html

C:\Program Files\MySQL\bin>mysqld

2013-11-14 19:46:01 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details)

C:\Program Files\MySQL\bin>mysql -u root mysql1

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

C:\Program Files\MySQL\bin>mysqld

2013-11-14 19:46:01 0 [警告] 不推荐使用具有隐式默认值的时间戳。请使用 --explicit_defaults_for_timestamp 服务器选项(有关更多详细信息,请参阅文档)

C:\Program Files\MySQL\bin>mysql -u root mysql1

错误 1045 (28000): 用户 'root'@'localhost' 访问被拒绝(使用密码:NO)

Notice: I don't have mysqld_safeor safe_mysqldfiles in MySQL version

注意:我在 MySQL 版本中没有mysqld_safesafe_mysqld文件

Could you please help me? Below you can see the dump file generated by the command:

请你帮助我好吗?下面可以看到命令生成的转储文件:

C:\mysqld --init-file=C:\mysql-init.txt


C:\Program Files\MySQL\bin>mysqld --init-file=C:\mysql-init.txt --console

2013-11-14 17:57:20 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated.     Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2013-11-14 17:57:20 5180 [Note] Plugin 'FEDERATED' is disabled.
2013-11-14 17:57:20 5180 [Note] InnoDB: The InnoDB memory heap is disabled
2013-11-14 17:57:20 5180 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked     functions
2013-11-14 17:57:20 5180 [Note] InnoDB: Compressed tables use zlib 1.2.3
2013-11-14 17:57:20 5180 [Note] InnoDB: Not using CPU crc32 instructions
2013-11-14 17:57:20 5180 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2013-11-14 17:57:20 5180 [Note] InnoDB: Completed initialization of buffer pool
2013-11-14 17:57:20 5180 [ERROR] InnoDB: .\ibdata1 can't be opened in read-write mode
2013-11-14 17:57:20 5180 [ERROR] InnoDB: The system tablespace must be writable!
2013-11-14 17:57:20 5180 [ERROR] Plugin 'InnoDB' init function returned error.
2013-11-14 17:57:20 5180 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2013-11-14 17:57:20 5180 [ERROR] Unknown/unsupported storage engine: InnoDB
2013-11-14 17:57:20 5180 [ERROR] Aborting
2013-11-14 17:57:20 5180 [Note] Binlog end
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'partition'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_METRICS'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_CMPMEM'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_CMP'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_LOCKS'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'INNODB_TRX'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'BLACKHOLE'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'ARCHIVE'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'MRG_MYISAM'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'MyISAM'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'MEMORY'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'CSV'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'sha256_password'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'mysql_old_password'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'mysql_native_password'
2013-11-14 17:57:20 5180 [Note] Shutting down plugin 'binlog'
2013-11-14 17:57:20 5180 [Note] mysqld: Shutdown complete

C:\Program Files\MySQL\bin>

采纳答案by Nabil

Your problem is here:

你的问题在这里:

2013-11-14 17:57:20 5180 [ERROR] InnoDB: .\ibdata1 can't be opened in read-write mode

There's some problem with the ibdata1 file - maybe the permissions have changed on it? Perhaps some other process has it open. Does it even exist?

ibdata1 文件有问题 - 也许它的权限已更改?也许其他一些进程打开了它。它甚至存在吗?

Fix this and possibly everything else will fall into place.

解决这个问题,其他一切可能都会就位。

回答by wcyn

I had the same problem. mysql -u root -pworked for me. It later asks you for a password. You should then enter the password that you had set for mysql. The default password could be password, if you did not set one. More info here.

我有同样的问题。mysql -u root -p为我工作。稍后它会要求您输入密码。然后您应该输入您为 mysql 设置的密码。password如果您没有设置,默认密码可以是。更多信息在这里

回答by user5144705

Follow the steps given below:

请按照以下步骤操作:

  1. Stop your MySQL server completely. This can be done by accessing the Services window inside Windows XP and Windows Server 2003, where you can stop the MySQL service.

  2. Open your MS-DOS command prompt using "cmd" inside the Run window. Inside it navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.

  3. Execute the following command in the command prompt: mysqld.exe -u root --skip-grant-tables

  4. Leave the current MS-DOS command prompt as it is, and open a new MS-DOS command prompt window.

  5. Navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.

  6. Enter mysqland press enter.

  7. You should now have the MySQL command prompt working. Type use mysql;so that we switch to the "mysql" database.

  8. Execute the following command to update the password:

    UPDATE user SET Password = PASSWORD('NEW_PASSWORD') WHERE User = 'root'; 
    
  1. 完全停止您的 MySQL 服务器。这可以通过访问 Windows XP 和 Windows Server 2003 中的服务窗口来完成,您可以在其中停止 MySQL 服务。

  2. 使用“运行”窗口中的“cmd”打开您的 MS-DOS 命令提示符。在其中使用 cd 命令导航到您的 MySQL bin 文件夹,例如 C:\MySQL\bin。

  3. 在命令提示符下执行以下命令: mysqld.exe -u root --skip-grant-tables

  4. 保持当前的 MS-DOS 命令提示符不变,并打开一个新的 MS-DOS 命令提示符窗口。

  5. 使用 cd 命令导航到您的 MySQL bin 文件夹,例如 C:\MySQL\bin。

  6. 输入mysql并按回车键。

  7. 您现在应该可以使用 MySQL 命令提示符了。键入use mysql;以便我们切换到“mysql”数据库。

  8. 执行以下命令更新密码:

    UPDATE user SET Password = PASSWORD('NEW_PASSWORD') WHERE User = 'root'; 
    

However, you can now run any SQL command that you wish.

但是,您现在可以运行任何您希望的 SQL 命令。

After you are finished close the first command prompt and type exit;in the second command prompt windows to disconnect successfully. You can now start the MySQL service.

完成后关闭第一个命令提示符并键入exit;第二个命令提示符窗口以成功断开连接。您现在可以启动 MySQL 服务。

回答by Ram Patra

The following steps are to reset the password for a user in case you forgot, this would also solve your mentioned error.

以下步骤是在您忘记的情况下为用户重置密码,这也可以解决您提到的错误。

First, stop your MySQL:

首先,停止你的 MySQL:

sudo /etc/init.d/mysql stop

Now start up MySQL in safe mode and skip the privileges table:

现在以安全模式启动 MySQL 并跳过权限表:

sudo mysqld_safe --skip-grant-tables &

Login with root:

使用 root 登录:

mysql -uroot

And assign the DB that needs to be used:

并分配需要使用的DB:

use mysql;

Now all you have to do is reset your root password of the MySQL user and restart the MySQL service:

现在您要做的就是重置 MySQL 用户的 root 密码并重新启动 MySQL 服务:

update user set password=PASSWORD("YOURPASSWORDHERE") where User='root';

flush privileges;

quit and restart MySQL:

退出并重启 MySQL:

quit

sudo /etc/init.d/mysql stop sudo /etc/init.d/mysql start Now your root password should be working with the one you just set, check it with:

sudo /etc/init.d/mysql stop sudo /etc/init.d/mysql start 现在您的 root 密码应该与您刚刚设置的密码一致,请检查:

mysql -u root -p

回答by Nabil

I encountered the same problem, probably when I uninstalled it and tried to install it again. This happens because of the database file containing login details is still stored in the pc, and the new password will not match the older one. So you can solve this by just uninstalling mysql, and then removing the left over folder from the C:drive (or wherever you must have installed).

我遇到了同样的问题,可能是当我卸载它并尝试再次安装它时。发生这种情况是因为包含登录详细信息的数据库文件仍存储在 PC 中,并且新密码与旧密码不匹配。因此,您只需卸载 mysql,然后从C:驱动器(或您必须安装的任何位置)中删除剩余的文件夹即可解决此问题。