How does WordPress modify the table prefix of a Mysql database?
We know that you can set a prefix for the WordPress database table. The default value is wp _. Many users use wp _ by default. For some reason (such as improving security) what should we do if we want to modify the prefix of WordPress data?
Before getting started
Modifying data is a highly risky task and must be done well before you begin.Database Backup, OrSet the blog status to maintenance.
Modify database prefix in wp-config.php
Open your wp-config.php file and change the database prefix wp _ to the prefix you want, such as wpjam _.
$ Table_prefix = 'wpjam _';
Modify data table name
Open PHPMySQL, find your database, and run the following SQL statement to change the prefixes of all database tables from wp _ to wpjam _.
RENAME table 'wp _ commentmeta' TO 'wpjam _ commentmeta ';
RENAME table 'wp _ comments 'TO 'wpjam _ comments ';
RENAME table 'wp _ links 'TO 'wpjam _ links ';
RENAME table 'wp _ options' TO 'wpjam _ options ';
RENAME table 'wp _ postmeta' TO 'wpjam _ postmeta ';
RENAME table 'wp _ posts' TO 'wpjam _ posts ';
RENAME table 'wp _ terms 'TO 'wpjam _ terms ';
RENAME table 'wp _ term_relationships 'TO 'wpjam _ term_relationships ';
RENAME table 'wp _ term_taxono'my 'TO 'wpjam _ term_taxonomy ';
RENAME table 'wp _ usermeta' TO 'wpjam _ usermeta ';
RENAME table 'wp _ users' TO 'wpjam _ users ';
Modify data in the Options table
Use the following statement to change the value of option_name starting with wp _ in the options table to start with wpjam.
Select replace (option_name, 'wp _ ', 'wpjam _') FROM wpjam_options;
Modify data in the UserMeta table
Use the following statement to change the value of meta_key starting with wp _ in the UserMeta table to start with wpjam.
Select replace (meta_key, 'wp _ ', 'wpjam _') FROM wpjam_usermeta;
Get it done, close the job!