使用方法:将以下代码保存为aaa.php文件,放到网站根目录下,访问就行了。
<?php
$hostname_blog = "localhost";//设定数据库地址地址,一般为localhost
$database_blog = "wordpress";//设定数据库名
$username_blog = "username";//设定数据库用户名
$password_blog = "password";//设定数据库密码
$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_"');
$tablelist = mysql_query("SHOW TABLES");
while($checklist = mysql_fetch_array($tablelist)) {
$optimization=mysql_query("OPTIMIZE TABLE `$checklist[0]`");
}
echo 'Done';
?>
原文+理论:
注:以上代码无法在PHP7上正常运行
|