技术宅改变世界 技术宅改变世界

wordpress修改表前缀

in Dev read (1457) 文章转载请注明来源!

一般重定义表前缀能起到一定防SQL注入的能力(即便wordpress没有漏洞,装的插件也有可能有吧),安装wordpress前可以设置表前缀,但我们已经安装好了,写了这么多对象,总不可能重新安装吧,所以只有自己改咯。

1、备份(重要)

请一定一定要备份!!!!主要操作数据库,而且操作失误后不备份的情况下,想恢复回去是很困难的。

 

2、修改配置文件

打开根目录下的 wp-config.php 文件找到 $table_prefix 将 wp_ 改成你想要修改的后缀,我就改成 ghostcir_ 好了。

$table_prefix  = 'ghostcir_';

3、修改表名

在phpmyadmin(只要能执行SQL语句就可以)下执行下面的SQL语句,要注意的是如果你安装了一些插件,可能需要修改的表名不止这些,所以改完后发现那些表没变化要手动另外修改。

RENAME table `wp_commentmeta` TO `ghostcir_commentmeta`;
RENAME table `wp_comments` TO `ghostcir_comments`;
RENAME table `wp_links` TO `ghostcir_links`;
RENAME table `wp_options` TO `ghostcir_options`;
RENAME table `wp_postmeta` TO `ghostcir_postmeta`;
RENAME table `wp_posts` TO `ghostcir_posts`;
RENAME table `wp_terms` TO `ghostcir_terms`;
RENAME table `wp_term_relationships` TO `ghostcir_term_relationships`;
RENAME table `wp_term_taxonomy` TO `ghostcir_term_taxonomy`;
RENAME table `wp_usermeta` TO `ghostcir_usermeta`;
RENAME table `wp_users` TO `ghostcir_users`;

4、修改options、usermeta表

做完了上面那些,网站已经可以访问了,但是这个时候你会发现你没法进后台了,提示 Sorry, you are not allowed to access this page ,这是因为还有一些表的字段没有修改。

UPDATE ghostcir_options SET option_name = 'ghostcir_user_roles' WHERE option_name = 'wp_user_roles';
UPDATE ghostcir_usermeta SET meta_key = 'ghostcir_capabilities' WHERE meta_key = 'wp_capabilities';
UPDATE ghostcir_usermeta SET meta_key = 'ghostcir_user_level' WHERE meta_key = 'wp_user_level';
UPDATE ghostcir_usermeta SET meta_key = 'ghostcir_user-settings-time' WHERE meta_key = 'wp_user-settings-time';
UPDATE ghostcir_usermeta SET meta_key = 'ghostcir_dashboard_quick_press_last_post_id' WHERE meta_key = 'wp_dashboard_quick_press_last_post_id';
UPDATE ghostcir_usermeta SET meta_key = 'ghostcir_capabilities' WHERE meta_key = 'wp_capabilities';
UPDATE ghostcir_usermeta SET meta_key = 'ghostcir_capabilities' WHERE meta_key = 'wp_capabilities';
UPDATE ghostcir_usermeta SET meta_key = 'ghostcir_capabilities' WHERE meta_key = 'wp_capabilities';

5、关于SQL语句

自己将SQL语句复制到记事本中,ctrl+hghostcir_ 替换成你自己的表前缀,貌似说的有点多余

Dev
发表新评论
博客已萌萌哒运行
© 2024 • Powered by Typecho • Theme for yotu
PREVIOUS NEXT
雷姆
拉姆