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.

  1. Refer to the following article to add a user to DB
    1. https://hk.godaddy.com/en/help/create-an-admin-user-in-the-wordpress-database-27023 (Recommended)
    2. https://help.one.com/hc/en-us/articles/17467509114385-How-to-add-an-Admin-User-to-the-WordPress-database
    3. https://wpengine.com/support/add-admin-user-phpmyadmin/
  2. 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.
  3. 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.
    1. 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".
  4. 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.
    1. Here are the 2 SQLs you need to run:
      1. UPDATE my_lovely_usermeta SET meta_key = REPLACE(meta_key, 'wp_', 'my_lovely_') WHERE meta_key LIKE 'wp_%';
      2. UPDATE my_lovely_options SET option_name = replace(option_name, 'wp_', 'my_lovely_') WHERE option_name LIKE 'wp_%';
    2. 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`.
    3. If you don't want to update via SQL, you can always do it manually.  The concept is identical.
Hope it helps someone.

Comments

Popular posts from this blog

TCPDF How to show/display Chinese Character?

How to fix fancy box/Easy Fancybox scroll not work in mobile

Wordpress Load balancing: 2 web servers 1 MySQL without any Cloud services