Last active
December 19, 2015 02:29
-
-
Save mkdizajn/5883302 to your computer and use it in GitHub Desktop.
MYSQL RESET AND RECOVER ROOT USER AND PASSWORD!!!! last resort create the root user if missing!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MYSQL RESET AND RECOVER ROOT USER AND PASSWORD!!!! | |
Stop the mysql demon process using this command : | |
sudo /etc/init.d/mysql stop | |
Start the mysqld demon process using the --skip-grant-tables option with this command | |
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking & | |
Because you are not checking user privs at this point, it's safest to disable networking. In Dapper, /usr/bin/mysgld... did not work. However, mysqld --skip-grant-tables did. | |
start the mysql client process using this command | |
mysql -u root | |
from the mysql prompt execute this command to be able to change any password | |
FLUSH PRIVILEGES; | |
Then reset/update your password | |
SET PASSWORD FOR root@'localhost' = PASSWORD('password'); | |
If you have a mysql root account that can connect from everywhere, you should also do: | |
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root'; | |
Alternate Method: | |
USE mysql | |
UPDATE user SET Password = PASSWORD('newpwd') | |
WHERE Host = 'localhost' AND User = 'root'; | |
And if you have a root account that can access from everywhere: | |
USE mysql | |
UPDATE user SET Password = PASSWORD('newpwd') | |
WHERE Host = '%' AND User = 'root'; | |
For either method, once have received a message indicating a successful query (one or more rows affected), flush privileges: | |
FLUSH PRIVILEGES; | |
Then stop the mysqld process and relaunch it with the classical way: | |
sudo /etc/init.d/mysql stop | |
sudo /etc/init.d/mysql start | |
If no root user is in the MYSQL.USER table create it with this! | |
insert into `user` (`Host`, `User`, `Password`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, `Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, `max_updates`, `max_connections`, `max_user_connections`) | |
values('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','','0','0','0','0'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment