首页 > 解决方案 > 如何根据行名复制 MySQL 行(1),然后更改行名(2)

问题描述

我有一个包含很多子站点的 WP 多站点。

  1. 我想使用 option_name“theme_mods_my-theme”复制所有行。
  2. 并在复制后将其更改为“theme_mods_my-new-theme”。
  3. 不得删除或更改原始的“theme_mods_my-theme”。

行名称是唯一的,但有多个表显示此行。这些行的值是唯一的。行名称出现在这些表中,例如:

任何帮助深表感谢。

我想我需要这样的东西:

INSERT INTO `mywpsite_17_options` (`option_id`, `option_name`, `option_value`, `autoload`)
VALUES
(31940, 'theme_mods_my-theme', '[The values]', 'yes');

唯一的事情是:

  1. 它需要搜索名称为 mywpsite_XX_options 的所有表
  2. 在每个表的 option_name 列中找到 theme_mods_my-theme
  3. 像上面一样复制(插入)到每个表中
  4. [值] 需要重复
  5. theme_mods_my-theme 需要改成 theme_mods_my-new-theme
  6. 我猜 option_id 也需要更改,因为它是一个新插入。

标签: mysqlwordpress

解决方案


您可以使用插入选择而不是复制和更新,例如:

   insert into mywpsite_18_options (col_theme_name, col2, col3 )
   select 'theme_mods_my-new-theme', col2, col3
   from mywpsite_18_options
   where col_theme_name =  'theme_mods_my-theme' 

但是您必须为每个表重新操作


推荐阅读