I am trying to set up a local copy of a production Wordpress blog. On production, I am a user but not an admin, so I am trying to change myself to an admin locally. I was follow
To set the capabilities
and user_level
your meta_key
value needs to match your database prefix. By default this is wp_
(resulting in wp_capabilities
and wp_user_level
) however it would be different in your case as you don't have a prefix. The proper capabilities
value is a:1:{s:13:"administrator";s:1:"1";}
.
-- delete any existing values for this user
DELETE FROM usermeta WHERE user_id=376 AND (meta_key LIKE '%capabilities' OR meta_key LIKE '%user_level')
-- insert the capabilities and user_level for user_id 376
INSERT INTO usermeta(user_id,meta_key,meta_value) VALUES(376, 'capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO usermeta(user_id,meta_key,meta_value) VALUES(376, 'user_level', 10);
Here is how to change assign a User to the Admin Role in WordPress using MySQL statements:
-- Look at the field called "id" in the result set
---
select * from wp_users
where user_login = 'WORDPRESS_USERNAME_GOES_HERE';
-- Substitute the above "id" value in the "user_id" field below.
-- This is an integer value so do not use quotes around it
-- For example if the above "id" is the value 10 then the resulting line would be: where user_id = 10
--
update wp_usermeta
set meta_value = 'a:1:{s:13:"administrator";s:1:"1";}'
where user_id = USER_ID_GOES_HERE
and meta_key = 'wp_capabilities';
-- Lastly execute this statement remembering to substitute the same "id" value
update wp_usermeta
set meta_value = '10'
where user_id = USER_ID_GOES_HERE
and meta_key = 'wp_user_level';
If you have already have your username and password then you just need to update capability and role into database.
Go to wp_user table and locate your ID from there i.e. in my case its 2. And then go to wp_usermeta and look for meta_key = wp_capabilities and user_id - 2. Edit that row and change meta_value to
a:1:{s:13:"administrator";s:1:"1";}.
Again go for meta_key = wp_user_level and user_id = 2. Edit that row and change meta_value to 10. Don't change other rows where user_id is not your own.
See my wp_users table.
See my wp_usermeta table.
Two queries will be fired something like these:
UPDATE `wp_usermeta` SET `meta_value` = '10' WHERE `wp_usermeta`.`umeta_id` =27;
UPDATE `wp_usermeta` SET `meta_value` = 'a:1:{s:13:"administrator";s:1:"1";}' WHERE `wp_usermeta`.`umeta_id` =26;