删除WordPress数据库中的多余冗余数据

WordPress使用久了,数据库里面有很多没用的东西,下面分享一个删除多余数据的代码,

//wordpress数据库多余数据删除
$hostname_blog = "localhost";//填写数据库主机,同wp-config.php
$database_blog = "user";//填写数据库名,同wp-config.php
$username_blog = "user";//填写数据库用户名,同wp-config.php
$password_blog = "password";//设定数据库密码,同wp-config.php
$blog = mysql_pconnect($hostname_blog, $username_blog, $password_blog) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_blog, $blog);
mysql_query('DELETE FROM wp_posts WHERE post_type = "revision"');
mysql_query('DELETE FROM wp_postmeta WHERE meta_key = "_edit_lock"');
mysql_query('DELETE FROM wp_postmeta WHERE meta_key = "_edit_last"');
mysql_query('DELETE FROM wp_commentmeta WHERE meta_key LIKE "%trash%"');
mysql_query('DELETE FROM wp_comments WHERE comment_approved = "trash"');
mysql_query('DELETE FROM wp_options WHERE option_name REGEXP "_transient_"');
mysql_query('DELETE FROM wp_postmeta WHERE meta_key = ‘_wp_attached_file’');
mysql_query('DELETE FROM wp_postmeta WHERE meta_key = ‘_wp_attachment_metadata’');
mysql_query("delete from wp_posts where (post_status='auto-draft' or post_status='inherit') and post_type='post'");
$tablelist = mysql_query("SHOW TABLES");
while($checklist = mysql_fetch_array($tablelist)) {
       $optimization=mysql_query("OPTIMIZE TABLE `$checklist[0]`");
}echo '清理完成!';
?>

在上面的代码第一句添加< ?php然后保存为
clean.php文件,上传到网站的目录,直接用浏览器打开这个文件就可以了。
或者使用下面的语句,删除自己想删除的内容

DELETE FROM wp_posts WHERE post_type = "revision"
DELETE FROM wp_postmeta WHERE meta_key = "_edit_lock"
DELETE FROM wp_postmeta WHERE meta_key = "_edit_last"
DELETE FROM wp_commentmeta WHERE meta_key LIKE "%trash%"
DELETE FROM wp_comments WHERE comment_approved = "trash"
DELETE FROM wp_options WHERE option_name REGEXP "_transient_"
DELETE FROM wp_postmeta WHERE meta_key = "_wp_attached_file"
DELETE FROM wp_postmeta WHERE meta_key = "_wp_attachment_metadata"
DELETE FROM wp_posts where (post_status='auto-draft' or post_status='inherit') and post_type='post'

直接登录phpmyadmin中运行sql语句就OK了,执行sql语句前请备份数据库以防万一。

【本站资源无偿免费分享,如果资源对你有用,希望动动手指点点下面的广告吧!以维持服务器运行】
如需 WordPress 优化加速、主题修改、故障解决等服务,可联系我购买付费服务: 点此联系我 | 近期站内热门福利:

本文最后更新于2年前 (2018-06-13),若有错误或已失效,请在下方留言或联系QQ87200080

未经允许禁止转载
本文地址:https://www.77nn.net/297.html
版权声明:本文为原创文章,版权归 讯沃blog 所有,未经允许,禁止任何单位或个人转载!

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝、微信、QQ扫一扫,即可进行扫码打赏哦

0
分享到:

评论3

4 + 8 =
  1. 感谢分享
    绿软吧(lvr8.com)7个月前 (03-01)  福建省厦门市 回复
    地板
  2. 感谢,我试试
    绿软吧1年前 (2019-07-11)  福建省厦门市 回复
    板凳
  3. 在用wp clean up插件,挺好用的
    电脑爱好者6年前 (2015-02-08)  河北省石家庄市 回复
    沙发
没有账号? 忘记密码?

社交账号快速登录