Change Wordpress user to admin

I am trying to create a local copy of Wordpress blogs. In production, I am a user, but not an administrator, so I'm trying to change myself to an administrator locally. I followed this on the blog to make myself an admin, so I ran the following SQL queries:

INSERT INTO usermeta(user_id,meta_key,meta_value) VALUES(376, 'wp_capabilities', 'a:1:{s:13:"administrator";b:1;}'); INSERT INTO usermeta(user_id,meta_key,meta_value) VALUES(376, 'wp_user_level', 10); 

Then I cleared the browser cookies and logged in again, but when I tried to go to http://localhost/wp-admin , I still got "You do not have sufficient permissions to access this page." I even went so far that I deleted my APC cache files and reloaded Nginx and PHP-FPM, which also did not change anything. Does anyone know anything else to try?

+6
source share
3 answers

To set capabilities and user_level , the meta_key value must match your database prefix. By default, this is wp_ (the result of wp_capabilities and wp_user_level ), however in your case it will be different since you do not have a prefix. The correct 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); 
+8
source

Here's how to change the user assignment of an 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'; 
+4
source

If you already have your username and password, you just need to update the features and role in the database.

Go to the wp_user table and find your identifier from there, that is, in my case, its 2. And then go to wp_usermeta and find meta_key = wp_capabilities and user_id - 2. Change this line and change meta_value to

 a:1:{s:13:"administrator";s:1:"1";}. 

Go again for meta_key = wp_user_level and user_id = 2. Edit this line and change meta_value to 10. Do not change other lines where user_id is not yours.

See the wp_users table. Look for the ID

See table wp_usermeta. Look for capabilities and roles

Two queries will run something like this:

 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; 
+3
source

All Articles