How to change the database prefix in WordPress

Last updated December 6th, 2023 00:28

You are probably using the WordPress content management system for your website. Then you may know, that this system uses a database to store content data such as articles, pages, users, meta information, and many others. In a basic installation, WordPress uses a total of 12 tables, each with its own prefix. The default prefix in WordPress is ‘_wp’. However, hackers can exploit this fact by specifically targeting such a prefix. For security reasons, it is therefore good to have a prefix other than the default. If you did not choose a different prefix during installation, you can learn how to change the database prefix in WordPress using the phpMyAdmin tool.

How to change the database prefix in WordPress

Back up your database first

Since you will be making changes to the content of the database of a live website, it is important to always back up the content beforehand. You can find a complete guide on how to back up a MySQL database using the phpMyAdmin tool here. How to back up a MySQL database using the phpMyAdmin tool.

Prepare the wp-config.php file

The wp-config.php file is the main configuration file for WordPress. It stores important data, including the database connection information such as the server name, username, password, and the table prefix. First, log in to the FTP of your website and open the root folder containing your WordPress installation.

In this folder, find the wp-config.php file and edit it. Look for the line that says “$table_prefix = ‘wp_’;” and modify the prefix to the new one you want to set, for example, “new_“.

Vyčerpání paměti u WordPressu po přechodu na verzi 6.2
Jak změnit prefix databáze ve WordPressu

How to change the database prefix in WordPress using phpMyAdmin

In the following step, log in to your MySQL database management where you will need to execute a command to rename the table prefix. You can rewrite the 12 basic tables using this command (modify the prefix ‘new_’ to your own):

Jak změnit prefix databáze ve WordPressu
				
					RENAME table `wp_commentmeta` TO `novy_commentmeta`;
RENAME table `wp_comments` TO `novy_comments`;
RENAME table `wp_links` TO `novy_links`;
RENAME table `wp_options` TO `novy_options`;
RENAME table `wp_postmeta` TO `novy_postmeta`;
RENAME table `wp_posts` TO `novy_posts`;
RENAME table `wp_terms` TO `novy_terms`;
RENAME table `wp_termmeta` TO `novy_termmeta`;
RENAME table `wp_term_relationships` TO `novy_term_relationships`;
RENAME table `wp_term_taxonomy` TO `novy_term_taxonomy`;
RENAME table `wp_usermeta` TO `novy_usermeta`;
RENAME table `wp_users` TO `novy_users`;
				
			

Substitute the command and let it run. If you have other tables in WordPress created by a plugin, in addition to the basic ones, add such a table to the list for the command.

				
					RENAME table `wp_nejakatabulka` TO `novy_nejakatabulka`;
				
			

The tables options and usermeta

WordPress also uses the basic prefix additionally in the options and usermeta tables. Here too, in the final step, it will be necessary to rewrite the data. You can do this with the following command:

				
					UPDATE `novy_options` SET option_name = REPLACE(option_name,'wp_','novy_') WHERE option_name LIKE '%wp_%';
				
			
				
					UPDATE `novyprefix_usermeta` SET meta_key = REPLACE(meta_key, 'wp_', 'novy_') WHERE meta_key LIKE 'swp_%';
				
			

Once you run these two commands, WordPress in MySQL will be modified with a new prefix, which you will log in with using the already modified wp-config.php file.

How to change the database prefix in WordPress – conclusion.

Changing the database prefix in WordPress is not technically as difficult as it may seem at first glance. However, it will help you increase the security of your website at least a little bit, especially if you choose a different login than “admin”. With WordPress in particular, I sometimes feel that its overall security depends precisely on individual details, which ultimately lead to keeping unauthorized persons out.

More content about WordPress

Whole category is here

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/ů
Nejstarší
Nejnovější Nejvíce hlasováno
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