开发者

mysql wildcard (ignore one/two characters in search)

开发者 https://www.devze.com 2022-12-17 02:27 出处:网络
I\'m trying to update tables in my wordpress mu database. I want to update all wp_options tables. These tables are named like this:

I'm trying to update tables in my wordpress mu database. I want to update all wp_options tables. These tables are named like this:

  • wp_1_options
  • wp_2_options
  • ...and so on.

How do i affect all tables with wp_any-character-here_options? I tried to query for:

UPDATE wp_%_options 
   SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') 
 WHERE option_name = 'home' OR option_name = 'siteurl';

...but mysql compla开发者_如何学Pythonins i have error in syntax...


You can't wildcard UPDATE statements - you have to write an UPDATE statement for each table.

Untested:

CREATE PROCEDURE cleanup()
BEGIN

  DECLARE i INT DEFAULT 1;

  PREPARE stmt FROM "UPDATE ? 
                        SET option_value = REPLACE(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') 
                      WHERE option_name IN ('home', 'siteurl')"

  WHILE i <= 10
    EXECUTE stmt USING CONCAT('wp_', i, '_options');

    SET i = i + 1;
  END WHILE;

  DEALLOCATE PREPARE stmt;

END;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号