在 WAMP 上重新获得对 PHPMyAdmin 丢失的 MySQL 密码的访问权限
我在 PHPMyAdmin 中更改了我的 'root'@'localhost' 帐户的密码(这个人在这里问) 并在我的浏览器上将自己锁定在 PHPMyAdmin 之外.我使用的是 WAMP 2.5.
I changed the password for my 'root'@'localhost' account in PHPMyAdmin and like (this person asking here) and locked myself out of PHPMyAdmin on my browser. I am using WAMP 2.5.
针对该问题提供的解决方案对我不起作用,因为不幸的是我丢失了将 root 重新分配给的密码.
The solutions offered on that question don’t work for me because unfortunately I have lost the password that I reassigned root to.
有些解决方案要求通过命令行重置密码(包括这个源),我已经通过 Windows 命令行尝试过但没有成功,因为我现在没有权限:
Some solutions ask one to reset the password via command line (including this source), and I have tried that through the Windows command line without success because I now have no privileges:
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('mynewpassword');
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
WAMP 带有 MySQL 控制台,但我无法使用它,因为它提示我输入密码,正如我所说,该密码不再存在.
WAMP comes with a MySQL Console but I am unable to use it since it prompts me for a password which as I stated, no longer have.
此视频说明了如何更改密码,与StackExchange 上面的回答,但显然,我现在需要另一种方法来做到这一点,因为我不知道我会像那个人警告的那样失去访问权限.
This video explains how to change passwords, and it agrees with the answers in the StackExchange answer above, but evidently, I need another method to do this now since I did not know I would lose access as the guy warns.
如果这是新手要问的问题,我将不胜感激,并表示歉意.我刚刚掌握了使用堆栈进行 Web 开发的窍门,并且通过 WAMP 配置对 LAN 站点的访问是一次冒险,所以如果可能的话,我更喜欢不需要重新安装所有东西的东西.
I would appreciate any advice and apologise if this is a newbie type of thing to ask. I am just getting the hang of using a stack for web development, and configuring access to a LAN site through WAMP was quite an adventure, so if possible, I would prefer something that does not require reinstalling everything again.
编辑 1:继续尝试@RiggsFolly 的解决方案.虽然我可以访问 my.ini
文件,毫无问题地进行更改,并通过 WAMP 或其他方式毫无问题地重新启动 MySQL,但行 skip-grant-tables
未生效,给我留下密码提示或无法执行任何操作.(我在这里写了一个新问题来解决这个问题,因为我觉得这是一个不同的问题.)
Edit 1: Went ahead and tried @RiggsFolly ’s solution. While I can access the my.ini
file, make changes without problem, and restart MySQL without issue through WAMP or otherwise, the line skip-grant-tables
is not taking effect, leaving me with a password prompt or no access to do anything. (I wrote a new question here to troubleshoot this since I feel like this is a different issue.)
Edit 2:我尝试了@t.niese 在评论中提供的链接中的说明,当我将控制台设置为返回对说明的反馈时,它报告了这一点,并且无法更改任何东西:
Edit 2: I tried the instructions in the link provided by @t.niese in the comments and when I set the console to return feedback on the instructions, it reported this, and failed to change anything:
C:\wamp\bin\mysql\mysql5.6.17\bin>mysqld --skip-grant-tables --console
[Note] Plugin 'FEDERATED' is disabled.
[Note] InnoDB: Using atomics to ref count buffer pool pages
[Note] InnoDB: The InnoDB memory heap is disabled
[Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions
[Note] InnoDB: Compressed tables use zlib 1.2.3
[Note] InnoDB: Not using CPU crc32 instructions
[Note] InnoDB: Initializing buffer pool, size = 128.0M
[Note] InnoDB: Completed initialization of buffer pool
[ERROR] InnoDB: .\ibdatai can't be opened in read-write mode
[ERROR] InnoDB: The system tablespace must be writabe!
[ERROR] Plugin 'InnoDB' init function returned error.
[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
[ERROR] Unknown/unsupported storage engine: InnoDB
[ERROR] Aborting
[Note] /* List of plugins shutting down */
推荐答案
这里有一种方法可以让您非常简单地重置 MYSQL 'root' 密码.
Here is a method that will allow you to reset the MYSQL 'root' password quite simply.
停止mysql服务
wampmanager -> MySQL -> Service -> Stop Service
编辑 my.ini 文件
Edit the my.ini file
wampmanager -> MySQL -> my.ini
在ini文件中找到[wampmysqld]
(32bit)或[wampmysqld64]
(64bit)部分
Find the [wampmysqld]
(32bit) or [wampmysqld64]
(64bit) section in the ini file
在该部分标题后直接添加此行
Add this line directly after that section heading
skip-grant-tables
重启mysql服务.
wampmanager -> MySQL -> Service -> Start/Resume Service
打开 MySQL 控制台
Open the MySQL console
wampmanager -> MySQL -> MySQL Console
现在我们要重置root用户的密码,当然这可以用来重置任何用户的密码.
Now we are going to reset the password for the root user, of course this could be used to reset any users password.
在mysql>
命令提示符下输入以下2条命令,每行最后一个分号,每行后按ENTER向mysql发出命令.
Enter the following 2 commands at the mysql>
command prompt, each with a semi colon at the end of a line, and press ENTER after each line to issue the command to mysql.
MYSQL 5.7 之前的版本
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;
发布 MYSQL 5.7 版后列名发生了变化
UPDATE mysql.user SET authentication_string=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;
请注意,更新可能会报告它更新了不止一行,因为可能有多个用户帐户的用户 ID 为root",每个帐户都具有不同的域,即 127.0.0.1、localhost 和::1
现在在 mysql 命令提示符处输入 'quit' 以存在 mysql.
Now enter 'quit' at the mysql command promt to exist mysql.
停止mysql服务
wampmanager -> MySQL -> Service -> Stop Service
编辑 my.ini 文件
Edit the my.ini file
wampmanager -> MySQL -> my.ini
在ini文件中找到[wampmysqld]
(32bit)或[wampmysqld64]
(64bit)部分
Find the [wampmysqld]
(32bit) or [wampmysqld64]
(64bit) section in the ini file
删除我们之前添加的 skip-grant-tables
参数.
Remove the skip-grant-tables
parameter we added earlier.
不要将此参数留在ini文件中,这是一个巨大的安全漏洞.
重启mysql服务.
wampmanager -> MySQL -> Service -> Start/Resume Service
现在,如果您愿意,您可以设置 root 用户帐户,使其不会自动使密码过期
Now if you want you can set the root user account so it does not expire the password automatically
wampmanager -> MySQL -> MySQL Console
然后运行这个查询
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
您现在应该可以使用用户 ID 'root' 和您刚刚为该用户设置的新密码通过 phpmyadmin 登录.
You should now be able to login with phpmyadmin using the userid 'root' and the new password you have just set for that user.
相关文章