If you only want to retain three out of 364K users, you DO NOT want to use DELETE
queries!
Instead, use the phpMyAdmin “Copy Table” feature (accessed from the Operations tab when viewing the table contents), and select the Structure only
option. You’ll need to do this with the wp_users
and wp_usermeta
tables, and give the new tables names of, say, wp_users2
and wp_usermeta2
. Change the table prefix from wp_
to the one in use on your site.
Now find the IDs of the three users you want to retain. Let’s say the IDs are 1, 8, and 44. Then run the following two queries (using the correct table prefix):
INSERT INTO wp_usermeta2 SELECT * FROM wp_usermeta WHERE user_id IN (1,8,44);
INSERT INTO wp_users2 SELECT * FROM wp_users WHERE ID IN (1,8,44);
You now have tables with only the users you want, but please inspect both before proceeding. If the new tables look OK, use phpMyAdmin to rename wp_users
and wp_usermeta
to something else (rename wp_users
first), and afterwards, rename wp_users2
and wp_usermeta2
to wp_users
and wp_usermeta
(rename wp_usermeta2
first). Your site will throw errors during the minute or so you do the renaming. If there are any issues with the new tables, revert the rename process to restore the original tables.
After you verify that your site is running fine with the two new tables, you can drop the two original tables since they are no longer needed.
Note: if you are using any type of cache plugin that caches DB queries, you should deactivate it before starting this process, and then re-enable it afterwards. This is called an object cache, and if the plugin has an option to disable its object cache, use that option as opposed to deactivating the plugin.