Add WordPress Admin User via Database 2024 (and onwards)
If you are trying to add a user (probably admin), not using UI but via database directly. Here is what you did.
- Refer to the following article to add a user to DB
- https://hk.godaddy.com/en/help/create-an-admin-user-in-the-wordpress-database-27023 (Recommended)
- https://help.one.com/hc/en-us/articles/17467509114385-How-to-add-an-Admin-User-to-the-WordPress-database
- https://wpengine.com/support/add-admin-user-phpmyadmin/
- They are all talking about same steps, so just pick one and follow. In case if you don't understand first article, read the next one and so on.
- Remember, if you are updating existing DB to use new prefix, you need to manually (or via SQL) update all table name to use your prefix.
- For example, if original prefix is 'wp_', and you want to change it to "my_lovely_", you need to update all table names, like "wp_posts" > "my_lovely_posts".
- Here is the missing steps: Thanks to my colleagues, you also need to update {prefix}_options and {prefix}_usermeta table, or you will find your self successfully login to WP, yet you will see a very very limited dashboard that, you can only "logout" but not doing anything.
- Here are the 2 SQLs you need to run:
- UPDATE my_lovely_usermeta SET meta_key = REPLACE(meta_key, 'wp_', 'my_lovely_') WHERE meta_key LIKE 'wp_%';
- UPDATE my_lovely_options SET option_name = replace(option_name, 'wp_', 'my_lovely_') WHERE option_name LIKE 'wp_%';
- As you can see, it simply means to update all rows with prefix "wp_" to your desired, custom prefix you defined in `wp-config.php`.
- If you don't want to update via SQL, you can always do it manually. The concept is identical.
Hope it helps someone.
Comments