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
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
提问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_safe
or safe_mysqld
files in MySQL version
注意:我在 MySQL 版本中没有mysqld_safe
或safe_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 -p
worked 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:
请按照以下步骤操作:
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.
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.
Execute the following command in the command prompt:
mysqld.exe -u root --skip-grant-tables
Leave the current MS-DOS command prompt as it is, and open a new MS-DOS command prompt window.
Navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
Enter
mysql
and press enter.You should now have the MySQL command prompt working. Type
use mysql;
so that we switch to the "mysql" database.Execute the following command to update the password:
UPDATE user SET Password = PASSWORD('NEW_PASSWORD') WHERE User = 'root';
完全停止您的 MySQL 服务器。这可以通过访问 Windows XP 和 Windows Server 2003 中的服务窗口来完成,您可以在其中停止 MySQL 服务。
使用“运行”窗口中的“cmd”打开您的 MS-DOS 命令提示符。在其中使用 cd 命令导航到您的 MySQL bin 文件夹,例如 C:\MySQL\bin。
在命令提示符下执行以下命令:
mysqld.exe -u root --skip-grant-tables
保持当前的 MS-DOS 命令提示符不变,并打开一个新的 MS-DOS 命令提示符窗口。
使用 cd 命令导航到您的 MySQL bin 文件夹,例如 C:\MySQL\bin。
输入
mysql
并按回车键。您现在应该可以使用 MySQL 命令提示符了。键入
use mysql;
以便我们切换到“mysql”数据库。执行以下命令更新密码:
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:
驱动器(或您必须安装的任何位置)中删除剩余的文件夹即可解决此问题。