Creating WordPress User’s in MySQL

Not to long ago, I found myself completely locked out of the dashboard of a WordPress site I needed access to.

The client changed their password but couldn’t remember what to. Thankfully I remembered that WordPress stores all metadata (like usernames, passwords, user roles & all other settings) in a MySQL database which I have access to.

Here’s what I did

Using Coda 2, I accessed the site’s core files on the client’s server. WordPress uses the wp-config.php file to store database connection information. Typically this file is created when WordPress is getting installed and as long as the site is working correctly doesn’t get much attention.

// ** MySQL settings — You can get this info from your web host ** // /** The name of the database for WordPress */ define(‘DB_NAME’, ‘database_name_here’); /** MySQL database username */ define(‘DB_USER’, ‘username_here’); /** MySQL database password */ define(‘DB_PASSWORD’, ‘password_here’); /** MySQL hostname */ define(‘DB_HOST’, ‘localhost’);

The DB_NAME, DB_USER, DB_PASSWORD, DB_HOST fields are what I needed.

I then copied the DB_HOST value and pasted it into my web browser, here I was then prompted to supply the DB_USER and DB_PASSWORD values. Once I did that I got into phpMyAdmin — a web editor for MySQL.

On the left hand side, I selected the database I needed (from DB_NAME) and then the SQL tab. In the run SQL query box, I dropped the following in and then hit go.

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 (‘21', ‘username_here’, MD5(‘password_here’), ‘Justin Chick’, ‘hey@justinchick.com’, ‘http://justinchick.com/', ‘2014–12–06 00:00:00', ‘’, ‘0', ‘Justin Chick’); INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, ‘21', ‘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, ‘21', ‘wp_user_level’, ‘10');

After that I went to dashboard login for WordPress and entered the username and password I just created and just like that, I was inside the dashboard.


Originally published at justinchick.com on December 8, 2014.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.