将以下命令所有清理数据库的语句汇总到一个php文件(SEOClear.php),
打开PHP文件后就可以直接优化清理数据了,并且保证是安全的。 粘贴以下代码执行PHP文件即可:
操作之前请备份好数据库,出问题不要找我,仅供参考:
<?php
//wordpress数据库优化清理脚本
$hostname_blog = "localhost";//设定数据库主机,同wp-config.php
$database_blog = "wordpress";//设定数据库名,同wp-config.php
$username_blog = "root";//设定数据库用户名,同wp-config.php
$password_blog = "";//设定数据库密码,同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 a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = "revision"');
mysql_query('DELETE FROM wp_posts WHERE NOT(post_status = "publish" AND post_type IN("post","nav_menu_item","page")');
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 != "1"');
mysql_query('DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL');
mysql_query('DELETE FROM wp_commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM wp_comments)');
mysql_query('DELETE FROM wp_term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM wp_posts)');
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 'Done';
//ps记得修改数据库前缀~
//使用时将脚本上传至网站任意目录后并且通过浏览器访问即可一键清理wordprsss数据库。
?>
© 版权声明
1.本站所有资源来源于用户上传与网络:如有侵权请邮件联系站长!
2.如有链接无法下载,失效,请加微信处理!
3.分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
4.不得使用于非法商业用途,不得违反国家法律法规,否则后果自负!
5.本站提供的源码,模板,插件等等其他资源,都不包含技术服务请大家谅解!
6.本站收费资源只是赞助,收取费用仅维持本站的服务器日常运营所需!
7.如遇到压缩包,默认解压密码为“ weichat.me ”,如遇到无法解压的请联系管理员!
8.由于精力有限,网站很多源码和模板都是从官网付费购买和网络收集下载的,没有办法逐一测试,不保证每个资源、软件可长期正常使用,请仔细确认是否真的必须购买,如有问题请自行处理,感谢理解。
THE END
暂无评论内容