How to Make Yourself an Admin in WordPress (via Database Access)

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Applicable when you have:

  • 🖥️ Server or cPanel access
  • 🗄️ Database access (phpMyAdmin or MySQL CLI)
  • ❌ No access to the WordPress Dashboard

Identify the Database in Use

Before anything, confirm which database your WordPress site is using.

  1. Go to your WordPress installation folder.
  2. Open the file: wp-config.php
  3. Look for these lines: define('DB_NAME', 'your_database_name'); define('DB_USER', 'your_db_user'); define('DB_PASSWORD', 'your_db_password'); define('DB_HOST', 'localhost'); $table_prefix = 'wp_';
  4. Note down the database name and table prefix (e.g., wp_, wz_, etc.).

Open phpMyAdmin

  1. Log into your server control panel (e.g., cPanel, XAMPP, or direct phpMyAdmin).
  2. Select your WordPress database from the left sidebar.
  3. You’ll see tables like: wp_users wp_usermeta wp_posts ... (Your prefix may differ, e.g., wz_users)

Check Existing Admin Users

You can easily see which users already have admin rights.

Option A: Manual (through phpMyAdmin)

  1. Open the wp_usermeta table.
  2. In the Search tab, find meta_key and enter: %capabilities%
  3. Check rows where meta_value contains: a:1:{s:13:"administrator";b:1;} The corresponding user_id is an admin.
  4. Go back to wp_users → find the same ID to see which username is the admin.

Option B: Using SQL Query

Run this SQL query directly:

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

This will list all admin accounts instantly.


Make Yourself an Admin (If You’re Not One Yet)

If you found your user in wp_users but not as an admin, you can assign admin privileges manually.

Step 1: Find your user_id

From wp_users, locate your username — for example:

IDuser_loginuser_email
19rajeshkumarrajesh@devopsschool.com

So here, your user_id = 19.


Step 2: Insert Admin Capabilities

Run these SQL statements (replace wp_ with your actual prefix, and 19 with your user ID):

INSERT INTO wp_usermeta (user_id, meta_key, meta_value)
VALUES (19, 'wp_capabilities', 'a:1:{s:13:"administrator";b:1;}');

INSERT INTO wp_usermeta (user_id, meta_key, meta_value)
VALUES (19, 'wp_user_level', '10');

That’s it — your account now has full administrator privileges.


Log in to WordPress Dashboard

  1. Go to your site admin page: https://yourdomain.com/wp-admin
  2. Log in with your existing credentials (same username and password from wp_users).
  3. You’ll now have complete access as an administrator.

Alternative Method (If phpMyAdmin Isn’t Available)

If you have file access but no database access, you can still make yourself admin through your theme.

Steps:

  1. Open your server’s file manager or FTP.
  2. Go to your active theme directory: /wp-content/themes/your-active-theme/
  3. Edit the file functions.php and add this code at the very end: function make_me_admin(){ $user = 'rajesh'; $pass = 'YourSecurePassword'; $email = 'rajesh@example.com'; if ( !username_exists( $user ) ) { $user_id = wp_create_user( $user, $pass, $email ); $user = new WP_User( $user_id ); $user->set_role( 'administrator' ); } } add_action( 'init', 'make_me_admin' );
  4. Save the file, then reload your site once in the browser.
    • WordPress will auto-create an admin user with those credentials.
  5. After logging in successfully, remove that code from functions.php immediately.

Optional: Reset Your Password via SQL

If you forgot your admin password, you can reset it directly in the database.

Run this command (replace with your username):

UPDATE wp_users SET user_pass = MD5('NewSecurePassword') WHERE user_login = 'rajesh';

Troubleshooting Tips

ProblemLikely CauseFix
You can’t log in even after inserting SQLWrong table prefixDouble-check prefix in wp-config.php
Login shows “Incorrect password”MD5 missing or wrongEnsure password uses MD5() in SQL
“Sorry, you are not allowed to access this page.”User not mapped correctlyRe-run both INSERT INTO wp_usermeta statements
You don’t know table namesCheck SHOW TABLES; in SQL or phpMyAdmin sidebar
You get duplicate key errorAlready have wp_capabilities entryUse UPDATE instead of INSERT

Summary

TaskSQL / Step
Find AdminsSELECT ... LIKE '%administrator%'
Make User Admin2x INSERT INTO wp_usermeta
Reset PasswordUPDATE wp_users SET user_pass = MD5('password')
Create Admin via CodeAdd snippet to functions.php

Recommended Best Practices

  • Always backup your database before making edits.
  • Remove any temporary PHP code after it runs.
  • Limit phpMyAdmin access to trusted IPs only.
  • Use strong passwords for all admin accounts.
  • Once restored, review the Users → All Users page in WordPress and clean up unwanted admin entries.

Senior Software Development Engineer at Cotocus

Related Posts

How to Fix wpDiscuz Not Replacing Default WordPress Comments in Block Themes

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now Many…

Read More

A Complete Guide to Reducing Image Sizes in a WordPress Website Using ImageMagick

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now Images…

Read More
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments