php 在本地主机上使用 XAMPP 重置 MySQL 根密码

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

Resetting MySQL Root Password with XAMPP on Localhost

php

提问by Codeeeeee

So for the past hour I've been trying to figure out how to reset my 'root' password for MySQL as I cannot log into PHPMyAdmin. I've tried changing the password in the config.inc.php file and searching through other methods. I cannot find a successful way. A few months ago I changed it as a test password but now I forget what it was. If anyone can help, that would be great. (I'm running on a Windows computer).

所以在过去的一个小时里,我一直在试图弄清楚如何为 MySQL 重置我的“root”密码,因为我无法登录 PHPMyAdmin。我已经尝试在 config.inc.php 文件中更改密码并通过其他方法进行搜索。我找不到成功的方法。几个月前,我将其更改为测试密码,但现在我忘记了它是什么。如果有人可以提供帮助,那就太好了。(我在 Windows 计算机上运行)。

回答by user3800108

You want to edit this file: "\xampp\phpMyAdmin\config.inc.php"

您要编辑此文件: "\xampp\phpMyAdmin\config.inc.php"

change this line:

改变这一行:

$cfg['Servers'][$i]['password'] = 'WhateverPassword';

to whatever your password is. If you don't remember your password, then run this command within the Shell:

无论您的密码是什么。如果您不记得密码,请在 Shell 中运行以下命令:

mysqladmin.exe -u root password WhateverPassword

where WhateverPassword is your new password.

其中,WhateverPassword 是您的新密码。

回答by insCode

Steps:

脚步:

  1. Open your phpMyadmin dashboard
  2. go to user accounts
  3. on the user section Get the root user and click [ Edit privileges ]
  4. in the top section you will find change password button [ click on it ]
  5. make a good pass and fill 2 pass field .
  6. now hit the Go button.
  1. 打开您的 phpMyadmin 仪表板
  2. 转到用户帐户
  3. 在用户部分获取root用户并单击[编辑权限]
  4. 在顶部,您会找到更改密码按钮 [单击它]
  5. 做好传球并填补2传球领域。
  6. 现在点击 Go 按钮。

7 . now open your xampp dir ( c:/xampp ) --> 8 . to phpMyadmin dir [C:\xampp\phpMyAdmin]

7 . 现在打开你的 xampp 目录 ( c:/xampp ) --> 8 。到 phpMyadmin 目录 [C:\xampp\phpMyAdmin]

  1. open [ config.inc.php ] file with any text editor
  1. 使用任何文本编辑器打开 [ config.inc.php ] 文件

10 .find [ $cfg['Servers'][$i]['auth_type'] = 'config';]line and replace 'config' to ‘cookie'

10 .find [ $cfg['Servers'][$i]['auth_type'] = 'config';] 行并替换'config' to ‘cookie'

  1. go to [ $cfg['Servers'][$i]['AllowNoPassword'] = true;] this line change ‘true' to ‘false'.
  1. 转到 [ $cfg['Servers'][$i]['AllowNoPassword'] = true;] 此行更改‘true' to ‘false'

last : save the file .

最后:保存文件。

here is a video linkin case you want to see it in Action [ click Here]

这是一个视频链接,如果您想在行动中看到它[点击这里]

回答by jRoB

You can configure it with the "XAMPP Shell" (command prompt). Open the shell and execute this command:

您可以使用“XAMPP Shell”(命令提示符)对其进行配置。打开外壳并执行以下命令:

mysqladmin.exe -u root password secret

mysqladmin.exe -u root password secret

回答by ofrommel

If you indeed forgot the root password to the MySQL server, you need to start it with the option skip-grant-tables. Search for the appropriate Ini-File my.ini(C:\ProgramData\MySQL Server ...or something like this) and add skip-grant-tablesto the section [mysqld]like so:

如果您确实忘记了 MySQL 服务器的 root 密码,则需要使用选项启动它skip-grant-tables。搜索适当的 Ini-File my.iniC:\ProgramData\MySQL Server ...或类似的内容)并添加skip-grant-tables到该部分,[mysqld]如下所示:

[mysqld]
skip-grant-tables

回答by Dung

Reset XAMPP MySQL root password through SQL update phpmyadmin to work with it:

通过 SQL 更新 phpmyadmin 重置 XAMPP MySQL root 密码以使用它:

-Start the Apache Server and MySQL instances from the XAMPP control panel. After the server started, open any web browser and go to http://localhost/phpmyadmin/. This will open the phpMyAdmin interface. Using this interface we can manager the MySQL server from the web browser.

- 从 XAMPP 控制面板启动 Apache 服务器和 MySQL 实例。服务器启动后,打开任何 Web 浏览器并转到http://localhost/phpmyadmin/。这将打开 phpMyAdmin 界面。使用此界面,我们可以从 Web 浏览器管理 MySQL 服务器。

-In the phpMyAdmin window, select SQL tab from the right panel. This will open the SQL tab where we can run the SQL queries.

- 在 phpMyAdmin 窗口中,从右侧面板中选择 SQL 选项卡。这将打开 SQL 选项卡,我们可以在其中运行 SQL 查询。

-Now type the following query in the textarea and click Go

- 现在在 textarea 中键入以下查询,然后单击 Go

  • "UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';"

  • hit go

  • "FLUSH PRIVILEGES;"

  • hit go

  • “更新 mysql.user SET Password=PASSWORD('password') WHERE User='root';”

  • 打去

  • “同花顺特权;”

  • 打去

-Now you will see a message saying that the query has been executed successfully.

- 现在您将看到一条消息,说明查询已成功执行。

-If you refresh the page, you will be getting a error message. This is because the phpMyAdmin configuration file is not aware of our newly set root passoword. To do this we have to modify the phpMyAdmin config file.

- 如果您刷新页面,您将收到一条错误消息。这是因为 phpMyAdmin 配置文件不知道我们新设置的 root 密码。为此,我们必须修改 phpMyAdmin 配置文件。

-Open the file C:\xampp\phpMyAdmin\config.inc.php in your favorite text editor. Search for the string:

- 在您喜欢的文本编辑器中打开文件 C:\xampp\phpMyAdmin\config.inc.php。搜索字符串:

$cfg\['Servers'\]\[$i\]['password'] = ''; and change it to like this, 
$cfg\['Servers'\]\[$i\]['password'] = 'password'; Here the ‘password' is what we set to the root user using the SQL query.
$cfg['Servers'][$i]['AllowNoPassword'] = false; // set to false for password required
$cfg['Servers'][$i]['auth_type'] = 'cookie'; // web cookie auth

-Now all set to go. Save the config.inc.php file and restart the XAMPP server.

- 现在一切准备就绪。保存 config.inc.php 文件并重新启动 XAMPP 服务器。

Modified from Source: http://veerasundar.com/blog/2009/01/how-to-change-the-root-password-for-mysql-in-xampp/

修改自来源:http: //veerasundar.com/blog/2009/01/how-to-change-the-root-password-for-mysql-in-xampp/

回答by maria

1.-In XAMPP press button Shell

1.-在 XAMPP 中按下按钮外壳

2.-place command:

2.-place命令:

mysqladmin -u root password

mysqladmin -u root password

New password: aqui colocar password ejemplo ′09876′

New password: aqui colocar password ejemplo ′09876′

3.-go on the local disk c: xampp \ phpMyAdmin open config.inic.php with notepad ++

3.-转到本地磁盘c:xampp\phpMyAdmin 用记事本++打开config.inic.php

5.- add the password and in AllowNoPassword change to false

5.- 添加密码并在 AllowNoPassword 中更改为 false

/* Authentication type and info */

$cfg['Servers'][$i]['auth_type'] = 'cookie';

$cfg['Servers'][$i]['user'] = 'root';

$cfg['Servers'][$i]['password'] = '09876';

$cfg['Servers'][$i]['extension'] = 'mysqli';

$cfg['Servers'][$i]['AllowNoPassword'] = false;

$cfg['Lang'] = '';

6.- save changes, clear browser cache and restart xampp

6.-保存更改,清除浏览器缓存并重新启动xampp

回答by Mohamed Aasif

On xampp -> Phpmyadmin -> config.inc 21st line you see:

在 xampp -> Phpmyadmin -> config.inc 第 21 行,您会看到:

$cfg['Servers'][$i]['password'] = '';

Add your password here and restart your xampp. The password will change.

在此处添加您的密码并重新启动您的 xampp。密码会改变。

回答by Anupam

For me much better way is to do it using terminal rather then PhpMyAdmin UI.

对我来说更好的方法是使用终端而不是 PhpMyAdmin UI。

The answer is copied from "https://gist.github.com/susanBuck/39d1a384779f3d596afb19fcad6b598c" which I have tried and it works always, try it out..

答案是从“ https://gist.github.com/susanBuck/39d1a384779f3d596afb19fcad6b598c”中复制的,我已经尝试过并且它始终有效,请尝试一下..

  • Open C:\xampp\mysql\bin\my.ini (MySQL config file)
  • Find the line [mysqld] and right below it add skip-grant-tables. Example:

    [mysqld] skip-grant-tables port= 3306 socket = "C:/xampp/mysql/mysql.sock" basedir = "C:/xampp/mysql" tmpdir = "C:/xampp/tmp" [...etc...]

  • This should allow you to access MySQL if you don't know your password.

  • Stop and start MySQL from XAMPP to make this change take effect.
  • Next, in command line, connect to MySQL:
  • 打开 C:\xampp\mysql\bin\my.ini(MySQL 配置文件)
  • 找到行 [mysqld] 并在其正下方添加 skip-grant-tables。例子:

    [mysqld] skip-grant-tables port= 3306 socket = "C:/xampp/mysql/mysql.sock" basedir = "C:/xampp/mysql" tmpdir = "C:/xampp/tmp" [...etc...]

  • 如果您不知道密码,这应该允许您访问 MySQL。

  • 从 XAMPP 停止并启动 MySQL 以使此更改生效。
  • 接下来,在命令行中,连接到 MySQL:

C:\xampp\mysql\bin\mysql.exe --user=root

C:\xampp\mysql\bin\mysql.exe --user=root

  • Once in MySQL command line "select" the mysql database:
  • 一旦在 MySQL 命令行“选择”mysql 数据库:

USE mysql;

USE mysql;

  • Then, the following command will list all your MySQL users:
  • 然后,以下命令将列出您的所有 MySQL 用户:

SELECT * FROM user \G;

SELECT * FROM user \G;

  • You can scan through the rows to see what the root user's password is set to. There will be a few root users listed, with different hosts.
  • To set root user's to have a password of your choice, run this command:
  • 您可以扫描行以查看 root 用户的密码设置为什么。将列出一些具有不同主机的 root 用户。
  • 要将 root 用户设置为您选择的密码,请运行以下命令:

UPDATE user SET password = PASSWORD('secret_pass') WHERE user = 'root';

UPDATE user SET password = PASSWORD('secret_pass') WHERE user = 'root';

  • -OR- To set all root user's to have a blank password, run this command:
  • - 或 - 要将所有 root 用户设置为空密码,请运行以下命令:

UPDATE user SET password = '' WHERE user = 'root';

UPDATE user SET password = '' WHERE user = 'root';

When you're done, run exit; to exit the MySQL command line.

完成后,运行exit;退出 MySQL 命令行。

Next, re-enable password checking by removing skip-grant-tablesfrom C:\xampp\mysql\bin\my.ini.

接下来,通过skip-grant-tables从 C:\xampp\mysql\bin\my.ini 中删除来重新启用密码检查。

Save changes, restart MySQL from XAMPP.

保存更改,从 XAMPP 重新启动 MySQL。

回答by RileyManda

Try this:sudo /Applications/XAMPP/xamppfiles/xampp security Then follow the instructions

试试这个:sudo /Applications/XAMPP/xamppfiles/xampp security 然后按照说明操作

回答by Makzino

Open the file C:\xampp\phpMyAdmin\config.inc.phpin your text editor. Search for the tags below and edit accordingly

C:\xampp\phpMyAdmin\config.inc.php在文本编辑器中打开文件。搜索下面的标签并相应地进行编辑

$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'password';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = true;

Where 'password' is your new password. In-between quotes.

其中“密码”是您的新密码。中间引号。

GO to your browser and visit link http://localhost/phpmyadmin/. Click on 'GO' without your new password. It would log you in and you would be able to see the "CHANGE PASSWORD". Proceed to change your password and you are done.

转到您的浏览器并访问链接http://localhost/phpmyadmin/。在没有新密码的情况下单击“开始”。它会让您登录,您将能够看到“更改密码”。继续更改您的密码,您就完成了。