How to add an admin user to WordPress using MySQL

WordPress is a content management system (CMS) based on PHP and MySQL technology. With MySQL and the phpMyAdmin tool, you can also control it when, for example, you don’t have access to the WordPress administration. In this article, I’ll show you how to add an admin user to WordPress using MySQL. This comes in handy when you can’t access the wp-admin panel for some reason, perhaps because you don’t have the correct user in the system.

How to add an admin user to WordPress using MySQL

To add a user, you’ll need access to the MySQL database and the phpMyAdmin tool. You should obtain the phpMyAdmin URL and database login credentials from your web hosting provider.

After logging into phpMyAdmin, click on the database name first, then choose the tab labeled SQL. On this tab, you can execute the following command.

				
					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 ('16', 'demo', MD5('demo'), 'Your Name', 'test@example.com', 'http://www.example.com/', '2022-09-01 00:00:00', '', '0', 'Your Name');

INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '3', '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, '3', 'wp_user_level', '10');
				
			

How to modify the command

In this command, replace “databasename” with the actual name of your database. Then choose a user ID that does not already exist, in this case, the user will have ID 16. The rest is apparent from the code below:

  • user_login: the username you will use to log in
  • user_pass: the user’s password in unencrypted format
  • user_nicename: The user’s real name
  • user_email: the user’s email address
  • user_url: the user’s website address, if applicable
  • user_registered: the user’s registration date
  • display_name: the user’s real name

Thanks to the modified command below, we will create a user with the username “test-user” and the password “mysecretpass”. This user will have administrator privileges.

				
					INSERT INTO `xxxxxx`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('16', 'test-user', MD5('mysecretpass'), 'Real Name', 'test@example.com', 'http://www.example.com/', '2023-09-01 00:00:00', '', '0', 'Real Name');
  
INSERT INTO `xxxxxx`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '16', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
  
INSERT INTO `xxxxxx`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '16', 'wp_user_level', '10');
				
			

How to Add an Admin User to WordPress Using MySQL

Conclusion

As you can see, adding an admin user to WordPress using MySQL isn’t as difficult as it might initially seem. It just requires a bit of practice and familiarity with working in MySQL. Before actually adding a user, I always recommend backing up the database just in case anything goes wrong. Please, don’t underestimate this step.

The website is created with care for the included information. I strive to provide high-quality and useful content that helps or inspires others. If you are satisfied with my work and would like to support me, you can do so through simple options.

Byl pro Vás tento článek užitečný?

Klikni na počet hvězd pro hlasování.

Průměrné hodnocení. 0 / 5. Počet hlasování: 0

Zatím nehodnoceno! Buďte první

Jak užitečný vidíte tento článek.

Sledujte mě na sociálních médiích.

Je mi líto, že pro Vás nebyl článek užitečný.

Jak mohu vylepšit článek?

Řekněte mi, jak jej mohu zlepšit.

newsletter

Subscribe to the Newsletter

Stay informed! Join our newsletter subscription and be the first to receive the latest information directly to your email inbox. Follow updates, exclusive events, and inspiring content, all delivered straight to your email.

Odebírat
Upozornit na
guest
0 Komentáře/ů
Vložené zpětné vazby.
Zobrazit všechny komentáře.

Pokud mi chcete napsat rychlou zprávu, využije, prosím, níže uvedený
kontaktní formulář. Děkuji.

Další Kontaktní údaje