A customer’s WordPress site needs to be migrated to a new host. The most important step is to export the MySQL data and then import it to the new server. The only thing the customer can provide is the FTP account of the website. After a little analysis, we came to the following conclusion:
- The customer has forgotten his WordPress username and password. There is no way to retrieve the password through the WordPress password retrieval function, and he cannot log in to the WordPress dashboard.
- There is no scheduled backup task set up on the server. The latest backup is from 3 months ago. In the past 3 months, the website has a lot of user-generated content. There is no way to directly migrate the site from a recent backup.
- The server password has also been forgotten. The MySQL user has restricted remote connections. Although the database connection information can be seen through wp-config.php, there is no way to export the data through the MySQL management tool.
- The only solution is to find a way to retrieve the WordPress username and password, log in to the WordPress dashboard, and install the database export plug-in to export the database.
List all users via function
Because we can log in to the server through FTP, we can use the function provided by WordPress to list all users, usingget_usersFunction is enough. Generally, the user with ID 1 is the administrator user of WordPress. If not, try other IDs one by one until you confirm which one is the administrator user. For security reasons, the above code must be deleted after modification.
Modify user password through function
Once we have the administrator user ID, we can passwp_reset_passwordFunction to reset the administrator user’s password, insert the following code into the theme’s functions.php and refresh the page of the following site. Where ‘123321’ is the new password and ‘1’ is the administrator user ID.
wp_reset_password('123321', 1);
Log in to the dashboard with a new password and install the wp sync db plug-in to export the database. Then import the database to the new server through phpMyAdmin or other tools. If you need to modify the domain name, you can directly use wp sync db to push the database to the new website. If necessary, try it yourself. I won’t go into details here.
