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语句前请备份数据库以防万一。
© 版权声明
THE END
- 最新
- 最热
只看作者