wordpress 数据库
WordPress Database is like a brain for your entire WordPress site because every single information is stored in there thus making it hacker’s favorite target. Spammers and hackers run automated codes for SQL injections. Well, unfortunately many people forget to change the database prefix while they install WordPress. This makes it easier for hackers to plan a mass attack by targeting the default prefix wp_. The smartest way you can protect your database is by changing the database prefix which is really easy to do on a site that you are setting up. But it takes a few steps to change the WordPress database prefix properly for your established site without completely messing it up.
WordPress数据库就像整个WordPress网站的大脑一样,因为每个信息都存储在其中,因此成为黑客最喜欢的目标。 垃圾邮件发送者和黑客为SQL注入运行自动代码。 好吧,不幸的是,许多人在安装WordPress时忘记更改数据库前缀。 这使黑客更容易通过针对默认前缀wp_来计划大规模攻击。 保护数据库的最明智的方法是更改数据库前缀,这在您要设置的站点上确实很容易做到。 但是需要采取一些步骤来为已建立的站点正确更改WordPress数据库前缀,而不会完全搞乱它。
(Video Tutorial)
If you don’t like the video or need more instructions, then continue reading.
如果您不喜欢该视频或需要更多说明,请继续阅读。
(Preparation)
We recommend that you backup your WordPress Database before you perform anything suggested in this tutorial. It is important to keep daily backups of your site, we recommend BackupBuddy plugin for doing that. Next thing we recommend is that you redirect your visitors to a temporary maintenance page.
我们建议您在执行本教程中建议的操作之前备份WordPress数据库 。 保留网站的日常备份非常重要,我们建议您使用BackupBuddy插件。 我们建议的下一步是将访问者重定向到一个临时维护页面 。
(Change Table Prefix in wp-config.php)
Open your wp-config.php file which is located in your WordPress root directory. Change the table prefix line from wp_ to something else like this wp_a123456_
打开位于WordPress根目录中的wp-config.php文件。 将表前缀行从wp_更改为类似wp_a123456_的其他内容
So the line would look like this:
因此,该行如下所示:
$table_prefix = 'wp_a123456_';
Note: You can only change it to numbers, letters, and underscores.
注意:您只能将其更改为数字,字母和下划线。
(Change all Database Tables Name)
You need to access your database (most likely through phpMyAdmin), and then change the table names to the one we specified in wp-config.php file. If you are using the cPanel WordPress hosting, then you can find the phpMyAdmin link in your cPanel. Look at the image below:
您需要访问数据库(最有可能通过phpMyAdmin),然后将表名更改为我们在wp-config.php文件中指定的表名。 如果您使用的是cPanel WordPress托管 ,则可以在cPanel中找到phpMyAdmin链接。 看下图:
There are a total of 11 default WordPress tables, so changing them manually would be pain.
共有11个默认的WordPress表,因此手动更改它们很麻烦。
That’s why to make things faster, we have a SQL query that you can use.
这就是为什么使事情更快,我们有一个您可以使用SQL查询。
RENAME table `wp_commentmeta` TO `wp_a123456_commentmeta`;
RENAME table `wp_comments` TO `wp_a123456_comments`;
RENAME table `wp_links` TO `wp_a123456_links`;
RENAME table `wp_options` TO `wp_a123456_options`;
RENAME table `wp_postmeta` TO `wp_a123456_postmeta`;
RENAME table `wp_posts` TO `wp_a123456_posts`;
RENAME table `wp_terms` TO `wp_a123456_terms`;
RENAME table `wp_termmeta` TO `wp_a123456_termmeta`;
RENAME table `wp_term_relationships` TO `wp_a123456_term_relationships`;
RENAME table `wp_term_taxonomy` TO `wp_a123456_term_taxonomy`;
RENAME table `wp_usermeta` TO `wp_a123456_usermeta`;
RENAME table `wp_users` TO `wp_a123456_users`;
You may have to add lines for other plugins that may add their own tables in the WordPress database. The idea is that you change all tables prefix to the one that you want.
您可能必须为其他插件添加行,这些行可能会在WordPress数据库中添加自己的表。 想法是将所有表前缀更改为所需的表前缀。
(The Options Table)
We need to search the options table for any other fields that is using wp_ as a prefix, so we can replace them. To ease up the process, use this query:
我们需要在选项表中搜索使用wp_作为前缀的任何其他字段,以便我们替换它们。 为了简化此过程,请使用以下查询:
SELECT * FROM `wp_a123456_options` WHERE `option_name` LIKE '%wp_%'
This will return a lot of results, and you need to go one by one to change these lines.
这将返回很多结果,您需要一个接一个地更改这些行。
(UserMeta Table)
Next, we need to search the usermeta for all fields that is using wp_ as a prefix, so we can replace it. Use this SQL query for that:
接下来,我们需要在usermeta中搜索所有使用wp_作为前缀的字段,因此我们可以替换它。 为此,请使用以下SQL查询:
SELECT * FROM `wp_a123456_usermeta` WHERE `meta_key` LIKE '%wp_%'
Number of entries may vary on how many plugins you are using and such. Just change everything that has wp_ to the new prefix.
条目数可能会因您使用的插件数量等而异。 只需将具有wp_的所有内容更改为新的前缀即可。
(Backup and Done)
You are now ready to test the site. If you followed the above steps, then everything should be working fine. Now, you should make a new backup of your database just to be on the safe side.
现在您可以测试该站点了。 如果您按照上述步骤进行操作,那么一切都会正常进行。 现在,为了安全起见,您应该对数据库进行新备份。
wordpress 数据库