MySQL to Find/Select WordPress Users with Administrator Capabilities

describe-wp_users
Every once in a while I find myself with access to a WordPress installation’s database before I have an Administrator account created for me. When I need to find which account users have an Administrator role, I use the following MySQL query to get select that list:

SELECT u.ID, u.user_login
FROM wp_users u, wp_usermeta m
WHERE u.ID = m.user_id
AND m.meta_key LIKE 'wp_capabilities'
AND m.meta_value LIKE '%administrator%'

Note: the query above assumes a database prefix of “wp_”. Also, be sure to make sure the meta_key wp_capabilities above uses the database prefix.

After running the WordPress database query above, you’ll see the user accounts that are Administrators. It will look something like this:

+------+------------+
| ID   | user_login |
+------+------------+
|    1 | edward     |
|    2 | jimmyjam   |
|    3 | run        |
| 1405 | slickrick  |
| 1658 | e40        |
+------+------------+

Ok, I’m not sure if I should have used a “JOIN” instead, but this is a query that will work when you have MySQL access to your WordPress database and you need a list of user accounts that are Administrators. This is how you select user accounts Administrators with MySQL on WordPress database.

Post written by Ed Reckers

Founder and lead web development consultant at Red Bridge Internet : San Francisco WordPress Developers and Consultants.

Leave a Reply