68

我最近注意到我的wp_options桌子似乎有点大。它包含 1161 行,大小约为 2.1mb。

我已经安装了Clean Options。看起来该插件的开发早在 2010 年就停止了,但它仍然完成了这项工作。

我现在有一长串可能孤立的条目。有没有一种简单的方法可以对这些进行排序,并确定哪些要删除,哪些要保留?此外,这是否会导致网站出现性能问题?

感谢您的阅读,欢迎任何想法!

更新:Clean Options 插件在列表中返回了一些瞬态,这使我发现wp_options表中有数百个瞬态文件。有一大堆看起来像:

  • _site_transient_browser_5728a0f1503de54634b3716638...
  • _site_transient_timeout_browser_03df11ec4fda7630a5...
  • _transient_feed_83dcaee0f69f63186d51bf9a4...
  • _transient_plugin_slugs
  • _transient_timeout_feed_83dcaee0f69f63186d51bf9a4b...

等等。就像我说的,有几百行看起来像这样。只丢弃它们是否安全?

谢谢

4

3 回答 3

151

You can safetly dump them. Wordpress and some plugins will re-create transients as needed. A transient is more or less the stored value from a complex query. The results are saved as a transient so that the system doesn't have to perform a common query over and over, instead it just looks for the transient if it exists and hasn't expired. Of course, make a backup of your database before making a change lest something goes wrong!

After backing everything up, you can run a mysql statement like this:

DELETE FROM `wp_options` WHERE `option_name` LIKE ('%\_transient\_%')

[EDIT: statement fixed with escape characters, after comment suggestion]

于 2012-08-16T20:32:46.943 回答
4

您可以删除瞬变,因为它们将被重新创建。由于故障情况或某些插件的设计问题,可能会累积过期瞬态。解决此问题的一种方法是删除过期的瞬态,同时允许当前的瞬态执行其功能。仅清除过期几天的瞬态,您就有机会监控哪些插件导致过时的瞬态,并采取任何措施来修复问题或报告问题。

下面将查找数据库中的任何 wp*option 表,并删除超过一周陈旧的五个最大的临时选项。这为任何插件提供了足够长的时间来删除它们将自行清除的选项。

#!/bin/bash

DBNAME="mydatabase"
DBUSER="${USER}"
DBPASSWD="secret"
MYSQLBIN=/usr/bin/mysql # OR MYSQLBIN=/usr/local/mysql/bin/mysql
MYSQL="${MYSQLBIN} -s -D ${DBNAME} -u ${DBUSER} -p${DBPASSWD}"
TMP=/var/tmp/
ENTRIES_FILE="${TMP}entries.$$"

# Find option tables
for OPTION_TABLE in $( echo 'show tables like "%wp%options";' | ${MYSQL} )
do
    # Find up to five large long expired transients
    ${MYSQL} > ${ENTRIES_FILE} <<EOF
    select option_name from ${OPTION_TABLE} where option_name in
        (select concat("_transient",substr(option_name,19))
            FROM ${OPTION_TABLE} WHERE option_name LIKE '_transient_timeout%' AND
            option_value < UTC_TIMESTAMP() - INTERVAL 1 WEEK order by option_value)
    order by length(option_value) desc limit 5;
EOF
    for OPTION in $( < ${ENTRIES_FILE} )
    do
        echo Deleting ${OPTION} from ${OPTION_TABLE}
        echo delete from ${OPTION_TABLE} where option_name = \"${OPTION}\"\; | ${MYSQL}
        if [[ $? -eq 0 ]]; then
            echo delete from ${OPTION_TABLE} where option_name = \"_transient_timeout${OPTION:10}\"\; | ${MYSQL}
        fi
    done
done
rm -f ${ENTRIES_FILE}
于 2016-02-28T19:01:59.303 回答
0

安装插件Delete Expired Transients以每天自动清理数据库。

于 2019-07-29T05:47:57.847 回答