Adding a WordPress Super Administrator user in phpMyAdmin
Sometimes, when using WordPress multisite network, instead of creating super admin user from dashboard, we may need to create super admin user from database with the help of SQL query.
In this tutorial, I will show you how to create Create Administrator User for WordPress in phpMyAdmin via SQL Query. We can do it in just two steps:
- Create a general administrator、
- Let's make our administrators super administrators.
Creating an administrator user in phpMyAdmin
First, in the first SQL query, we create a regular WordPress user.
INSERT INTO wp_users ( user_login, user_pass, user_nicename, user_email, user_url, user_registered, display_name)
VALUES ( 'amos', MD5('myPasswrd'), 'amos', 'no-reply@amos.com', 'https://wpzhiku.com', '2023-04-14 09:25:20', 'Amos Lee' ) ;
Then, we assign the WordPress administrator role to this user
INSERT INTO wp_usermeta (user_id, meta_key, meta_value)
VALUES ( 2, 'wp_capabilities', 'a:1:{s:13: "administrator";b:1;}' )

Wait a minute. We're not talking aboutWordPress MultisiteWhy do we only use a regular WordPress database? Why do we just use the regular WordPress database?wp_users和wp_usermetaColumns? If you have such a question, I recommend you to read my other article onMulti-site database structureThe tutorial.
Make users super administrators of multi-site networks
This question is actually a bit tricky.
Information about super administrators in a multisite network is stored as site elements in thewp_sitemetaTable.There is only one option.This option most likely already exists. This means that we can use theUPDATESQL query to replace the existing superadmin with our new superadmin, like this:
UPDATE wp_sitemeta SET site_admins='a:1:{i:0;s:9: "rudrastyh";}' WHERE site_id=1;
Please note that after running this query, all existing Super Administrators will no longer be Super Administrators! Therefore, you'd better change this option manually. But what does it say?site_adminsWhat exactly is the value of
It's simple, it's just a serialized array of usernames, for exampleArray( 'rudrastyh' ) maybeArray( 'misha', 'rudrastyh')‘ ), so you can useserialize()PHP function or any online tool to convert it to aa:2:{i:0;s:5: "misha";i:1;s:9: "rudrastyh";}. You can even do the formatting yourself:
a:2.- Represents an array of 2 elements,i:0;s:5: - indicates that the first element of the array is a string of length 5, i.1;s:9: - Indicates that the second element of the array is a string of length 9.
If you try to retrieve or change your WordPress administrator password, please refer to this site's article onRetrieve WordPress PasswordThe article.