{"id":25182,"date":"2018-01-30T02:51:37","date_gmt":"2018-01-30T08:51:37","guid":{"rendered":"https:\/\/www.rosehosting.com\/blog\/?p=25182"},"modified":"2022-12-05T06:45:48","modified_gmt":"2022-12-05T12:45:48","slug":"how-to-reset-wordpress-admin-password-via-mysql-command-prompt","status":"publish","type":"post","link":"https:\/\/www.rosehosting.com\/blog\/how-to-reset-wordpress-admin-password-via-mysql-command-prompt\/","title":{"rendered":"How to Reset WordPress Admin Password via MySQL Command Prompt"},"content":{"rendered":"
<\/p>\n
Have you ever forgotten your WordPress administrator password and did not have access to your e-mail account or haven’t configured your e-mail account properly in WordPress? Fear not, because in today’s tutorial we are going to learn how to reset the WordPress administrator password through the MySQL command prompt.\u00a0Resetting WordPress Admin Password via MySQL Command Prompt, its fairly easy task, you will need to have the login credentials of your database and user, or have access to wp-config.php file. Let’s get started!<\/p>\n
Let’s begin by looking up the username and password you set for your WordPress database in your wp-config.php file first, do that by navigating to the directory WordPress is installed in and then open wp-config.php with nano:<\/p>\n
# nano wp-config.php<\/pre>\nFind the following lines in your wp-config.php file:<\/p>\n
\/\/ ** MySQL settings - You can get this info from your web host ** \/\/\r\n\/** The name of the database for WordPress *\/\r\ndefine( 'DB_NAME', 'database_name_here' );\r\n\/** MySQL database username *\/\r\ndefine( 'DB_USER', 'username_here' );\r\n\/** MySQL database password *\/\r\ndefine( 'DB_PASSWORD', 'password_here' );\r\n\/** MySQL hostname *\/\r\ndefine( 'DB_HOST', 'localhost' );\r\n<\/pre>\nNow that we have all the information we need we are going to open a MySQL command prompt with the following command:<\/p>\n
# mysql -u username_here -p -d database_name_here<\/pre>\nEnter the password when prompted and then enter the following query in the MySQL command prompt:<\/p>\n
mysql> use 'database_name_here';\r\nReading table information for completion of table and column names\r\nYou can turn off this feature to get a quicker startup with -A\r\n\r\nDatabase changed\r\n<\/pre>\nLook for the users table with the following query:<\/p>\n
mysql> show tables LIKE '%users';\r\n+---------------------------------------+\r\n| Tables_in_database_name_here (%users) |\r\n+---------------------------------------+\r\n| wp_users |\r\n+---------------------------------------+\r\n1 row in set (0.00 sec)\r\n<\/pre>\nUse the prefixed users table from the output of the query above in the following query, for an example we’ll use ‘wp_users’. We also use ‘admin’ as the administrator user, your administrator username might be different:<\/p>\n
mysql> SELECT ID, user_login, user_pass FROM wp_users WHERE user_login = 'admin';\r\n+----+------------+------------------------------------+\r\n| ID | user_login | user_pass |\r\n+----+------------+------------------------------------+\r\n| 1 | admin | $P$BiD1utsVDNrPVFm7.wcwPGzc.rKbu5. |\r\n+----+------------+------------------------------------+\r\n1 row in set (0.00 sec)\r\n<\/pre>\nThe query above outputs a row containing the current encrypted WordPress password of the administrator user, we are going to change it using this query, be sure to substitute ‘new_password’ for your own password:<\/p>\n
mysql> UPDATE wp_users SET user_pass=MD5('new_password') WHERE user_login = 'admin';\r\nQuery OK, 1 row affected (0.01 sec)\r\nRows matched: 1 Changed: 1 Warnings: 0\r\n<\/pre>\nNow check if the password has changed:<\/p>\n
mysql> SELECT ID, user_login, user_pass FROM wp_users WHERE user_login = 'admin';\r\n+----+------------+----------------------------------+\r\n| ID | user_login | user_pass |\r\n+----+------------+----------------------------------+\r\n| 1 | admin | 88162595c58939c4ae0b35f39892e6e7 |\r\n+----+------------+----------------------------------+\r\n1 row in set (0.00 sec)\r\n<\/pre>\nThen type exit to exit the MySQL command prompt:<\/p>\n
mysql> exit\r\nBye\r\n<\/pre>\nResetting the WordPress admin password through wp-cli<\/h2>\n
If you do not want to bother going the long route through MySQL you can change your WordPress administrator password with a neat tool called wp-cli which is considered the swiss army knife of WordPress. To download wp-cli execute the following command:<\/p>\n
# curl -O https:\/\/raw.githubusercontent.com\/wp-cli\/builds\/gh-pages\/phar\/wp-cli.phar<\/pre>\nCheck if wp-cli is working:<\/p>\n
# php wp-cli.phar --info<\/pre>\nThen make wp-cli executable and move it to ‘\/usr\/local\/bin’:<\/p>\n
# chmod +x wp-cli.phar\r\n# mv wp-cli.phar \/usr\/local\/bin\/wp<\/pre>\nNow navigate to the root directory of your WordPress installation and then execute the following wp-cli command:<\/p>\n
# wp user update admin --user-pass=new_password<\/pre>\nAgain, make sure that you replace ‘admin’ with your WordPress administrator username and ‘new_password’ with your desired password.<\/p>\n
If you are running wp-cli as root then add the ‘–allow-root’ option at the end of the command like this:<\/p>\n
# wp user update admin --user-pass=new_password --allow-root<\/pre>\nThat’s it, now you should have successfully changed the password for your WordPress administrator user.<\/p>\n
Of course, you don\u2019t have to\u00a0reset WordPress admin password via MySQL command prompt yourself, if you use one of our WordPress Hosting<\/a> services, in which case you can simply ask our expert Linux admins to change your WordPress administrator password for you. They are available 24\u00d77 and will take care of your request immediately.<\/p>\n
PS. If you liked this post on how to reset WordPress admin password via MySQL command prompt, please share it with your friends on the social networks using the buttons on the right or simply leave a reply below. Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"
Have you ever forgotten your WordPress administrator password and did not have access to your e-mail account or haven’t configured … <\/p>\n