Monday, September 30, 2013

Wordpress: Adding an admin user in phpMyAdmin

Sometimes you need admin access to a Wordpress site even though you had nothing to do with it before. If your college with the password is not available, you are in trouble.

You could overwrite the current admin user's password, but if you forget to change it back after you are finished, you could cause more harm than good. Also you might need access again for the same page.

The better solution is to create an admin user for yourself. For this you need to insert data in three seperate tables, so it is not as simple as I first thought it would be.

Use, so use these mysql commands tailored to your needs to quickly add your admin user.

 INSERT INTO `databasename`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('4', 'demo', MD5('demo'), 'Syed Balkhi', '', '', '2011-06-07 00:00:00', '', '0', 'Syed Balkhi');  
 INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');  
 INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_user_level', '10');  

Do not forget to change 'databasename' to the actual database name. Also check if the tables are prefixed by 'wp_' or something else. I also changed the users 'ID' value from 4 to 2 as my database had only one user. You should check what's the latest user's ID is and add one to it. Of course change the user name and password from demo to something else too, and change other data like alias, email, url and display name for good measure...


Important update:

Tinymce didn't work with the new admin user, only the html view was available. To enable the wysiwyg view, edit the new user and save it. This will re-save it's metas and fix tinymce...