Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
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.
- Go to your WordPress installation folder.
- Open the file:
wp-config.php
- 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_';
- Note down the database name and table prefix (e.g.,
wp_
,wz_
, etc.).
Open phpMyAdmin
- Log into your server control panel (e.g., cPanel, XAMPP, or direct phpMyAdmin).
- Select your WordPress database from the left sidebar.
- 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)
- Open the
wp_usermeta
table. - In the Search tab, find
meta_key
and enter:%capabilities%
- Check rows where meta_value contains:
a:1:{s:13:"administrator";b:1;}
The correspondinguser_id
is an admin. - Go back to
wp_users
โ find the sameID
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:
ID | user_login | user_email |
---|---|---|
19 | rajeshkumar | rajesh@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
- Go to your site admin page:
https://yourdomain.com/wp-admin
- Log in with your existing credentials (same username and password from
wp_users
). - 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:
- Open your serverโs file manager or FTP.
- Go to your active theme directory:
/wp-content/themes/your-active-theme/
- 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' );
- Save the file, then reload your site once in the browser.
- WordPress will auto-create an admin user with those credentials.
- 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
Problem | Likely Cause | Fix |
---|---|---|
You canโt log in even after inserting SQL | Wrong table prefix | Double-check prefix in wp-config.php |
Login shows โIncorrect passwordโ | MD5 missing or wrong | Ensure password uses MD5() in SQL |
โSorry, you are not allowed to access this page.โ | User not mapped correctly | Re-run both INSERT INTO wp_usermeta statements |
You donโt know table names | Check SHOW TABLES; in SQL or phpMyAdmin sidebar | |
You get duplicate key error | Already have wp_capabilities entry | Use UPDATE instead of INSERT |
Summary
Task | SQL / Step |
---|---|
Find Admins | SELECT ... LIKE '%administrator%' |
Make User Admin | 2x INSERT INTO wp_usermeta |
Reset Password | UPDATE wp_users SET user_pass = MD5('password') |
Create Admin via Code | Add 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.
Leave a Reply