Lần đầu cài đặt WordPress gợi ý table prefix là wp_. Ta không đổi giá trị này vẫn được, tuy nhiên, việc giữ những giá trị cài đặt mặc định sẽ khiến cho website của ta vô cùng yếu ớt đối với những kẻ phá hoại.
Ví dụ mình muốn thay thế wp_ bằng mytableprefix_
1. Edit file wp-config.php
Tìm biến $table_prefix trong file wp-config.php và đổi giá trị wp_ thành mytableprefix_
$table_prefix = 'mytableprefix_';
2. Rename database table bằng SQL
Truy cập database trên hosting của website và chạy những câu query bên dưới để đổi tên các table có liên quan.
RENAME table `wp_commentmeta` TO `mytableprefix_commentmeta`; RENAME table `wp_comments` TO `mytableprefix_comments`; RENAME table `wp_links` TO `mytableprefix_links`; RENAME table `wp_options` TO `mytableprefix_options`; RENAME table `wp_postmeta` TO `mytableprefix_postmeta`; RENAME table `wp_posts` TO `mytableprefix_posts`; RENAME table `wp_termmeta` TO `mytableprefix_termmeta`; RENAME table `wp_terms` TO `mytableprefix_terms`; RENAME table `wp_term_relationships` TO `mytableprefix_term_relationships`; RENAME table `wp_term_taxonomy` TO `mytableprefix_term_taxonomy`; RENAME table `wp_usermeta` TO `mytableprefix_usermeta`; RENAME table `wp_users` TO `mytableprefix_users`;
3. Rename field wp_ trong table _options và _usermeta
Cuối cùng, ta cập nhật tên các field có liên quan trong table _options và _usermeta.
UPDATE `mytableprefix_options` SET `option_name` = REPLACE(`option_name`,'wp_','mytableprefix_') WHERE `option_name` LIKE '%wp_%'; UPDATE `mytableprefix_usermeta` SET `meta_key` = REPLACE(`meta_key`,'wp_','mytableprefix_') WHERE `meta_key` LIKE '%wp_%';