因此,在过去的一个小时里,我一直在想如何为 MySQL 重置我的“ root”密码,因为我无法登录 PHPMyAdmin。我尝试过更改 config.inc.php 文件中的密码,并通过其他方法进行搜索。我找不到一个成功的方法。几个月前,我把它改成了一个测试密码,但现在我忘了它是什么了。如果有人能帮忙,那就太好了。(我在 Windows 电脑上运行)。
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-tables to the section [mysqld] like so:
Reset XAMPP MySQL root password through SQL update phpmyadmin to work with it:
-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.
-In the phpMyAdmin window, select SQL tab from the right panel. This will open the SQL tab where we can run the SQL queries.
-Now type the following query in the textarea and click Go
"UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';"
hit go
"FLUSH PRIVILEGES;"
hit go
-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.
-Open the file C:\xampp\phpMyAdmin\config.inc.php in your favorite text editor.
Search for the string:
$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.
SIMPLE STRAIGHT FORWARD WORKING SOLUTION AND OUT OF THE BOX:
1 - Start the Apache Server and MySQL instances from the XAMPP control panel.
2 - After the server started, open any web browser and give http://localhost/phpmyadmin/. This will open the phpMyAdmin interface. Using this interface we can manage the MySQL server from the web browser.
3 - In the phpMyAdmin window, select SQL tab from the top panel. This will open the SQL tab where we can run the SQL queries.
4 - Now type the following query in the text area and click Go
UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
FLUSH PRIVILEGES;
5 - Now you will see a message saying some thing like: the query has been executed successfully.
6 - 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.
7 - Open the file [XAMPP Installation Path]/phpmyadmin/config.inc.php in your favorite text editor (e.g: C:\xampp\phpMyAdmin\config.inc.php).
8 - Search for the string
$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.
9 - Now all set to go. Save the config.inc.php file and restart the XAMPP apache and mysql servers. It should work!
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.
Start the Apache Server and MySQL instances from the XAMPP control panel.
Now goto to your localhost.
Click on user accounts -> Click on Edit privileges -> You will find an option change password just change password as you want click on go. Image are given below
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.
Open terminal window (not mac default terminal please check attached image)
Then Run apt-get update in the newly opened terminal.
Then run apt-get install nano this will install nano
Open the XAMPP control panel and click on the shell and open the shell.
In the shell run the following :
mysql -h localhost -u root -p
and press enter. It will as for a password, by default the password is blank so just
press enter
Then just run the following query
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpassword');
and press enter and your password is updated for root user on localhost
Here, I couldn't use the default command (mysqladmin) suggested in previous steps. Then I followed following steps.
cd into mysql bin directory inside the XAMPP directory.
> cd C:\<xampp_installed_directory>\mysql\bin\
Run the following command in order to log into MySQL server via the command line without the password,
> mysql
Run the following commands in order to reset the password [2],
> USE mysql
> FLUSH PRIVILEGES;
> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
> exit
Verify the credentials by running the following command and enter the password you set in previous step.
> mysql -u root -p
If you can see the MySQL prompt. Then you're good to go!
Resetting the changes
After that, remove the line you added to MySQL config file at C:\<xampp_installed_directory>\mysql\bin\my.ini
Restart the server (Stop the server and Start the server) to affect the changes.
Change the auto login feature to login using credentials
Seems like by default phpMyAdmin has enabled the auto login [3]. Disabled that feature as following,
Edit the phpMyAdmin config file at C:\<xampp_installed_directory>\phpMyAdmin and find the auth_type config and change it as following (you can refer to the steps mentioned in [3] as well)
$cfg['Servers'][$i]['auth_type'] = 'cookie';
Restart the Apache server (Stop the server and Start the server) to affect the changes.