我可以在我的WordPress安装的wp_options表中删除暂存器吗?[英] Can I remove transients in the wp_options table of my WordPress install?

本文是小编为大家收集整理的关于我可以在我的WordPress安装的wp_options表中删除暂存器吗?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我最近注意到我的wp_options表似乎有点大.它包含1161行,大小约为2.1MB.

我已经安装了干净的选项.看起来2010年的开发在插件上停止了,但它仍然完成了工作.

我现在有一长串潜在的孤儿条目.是否有一种简单的方法可以解决这些问题,并弄清楚要删除哪个以及保留哪些?另外,这是否负责引起网站的性能问题?

谢谢您的阅读,任何想法都受到欢迎!

更新:干净的选项插件返回了列表中的一些瞬变,这使我发现wp_options表中有数百个瞬态文件.有一堆看起来像:

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

等等.就像我说的那样,有几百行看起来像这样.抛弃它们是安全的吗?

谢谢

推荐答案

您可以安全地倾倒它们. WordPress和某些插件将根据需要重新创建瞬变.瞬态或多或少是从复杂查询中存储的值.结果被保存为瞬态,因此系统不必一遍又一遍地执行常见的查询,而是在瞬态转移时,如果存在并且未过期.当然,在做出更改之前,请备份数据库,以免出现问题!

备份所有内容后,您可以运行这样的MySQL语句:

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

[编辑:用逃生字符修复的语句,在评论建议之后]

其他推荐答案

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

以下将在数据库中找到任何WP*选项表,并删除超过一周的五个最大瞬态选项.这给了足够长的时间,以删除将要清除自己的选项.

#!/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}

其他推荐答案

安装插件删除过期的瞬态以自动清理数据库每天.

本文地址:https://www.itbaoku.cn/post/597407.html

问题描述

I have recently noticed that my wp_options table seems to be a bit large. It contains 1161 rows, and is about 2.1mb in size.

I have installed Clean Options. It looks like development stopped on the plugin back in 2010, but it still did the job.

I now have a long list of potentially orphaned entries. Is there an easy way to go about sorting these, and figuring out which to remove and which to keep? Also, could this be responsible for causing performance issues with the website?

Thank you for reading, any ideas are welcomed!

Update: The Clean Options plugin returned some transients in the list, which lead me to find out that there are several hundred transient files in the wp_options table. There are a whole bunch that look like:

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

and so on. Like I said, there are several hundred rows that take look like this. Is it safe to just dump them?

Thanks

推荐答案

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]

其他推荐答案

You can delete transients as they will be recreated. There can be buildups of expired transients due to failure situations or design issues with some plugins. One way of coping with this is to remove expired transients while allowing current ones to perform their function. Purging only transients which are expired for a few days gives you a chance to monitor which plugins are resulting in stale transients, and take any action to fix issues or report issues.

The following will find any wp*option tables in the database and delete the five largest transient options which are more than a week stale. This gives long enough for any plugin to delete options which they are going to purge themselves.

#!/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}

其他推荐答案

Install the plugin Delete Expired Transients to automatically clean up the database on a daily basis.