MySQL暴力字符串替换

单库 全表 替换

CREATE DEFINER=`root`@`%` PROCEDURE `replace_url_in_all_tables`()
BEGIN
    DECLARE done INT DEFAULT 0;
    DECLARE current_table_name VARCHAR(255);
    DECLARE current_column_name VARCHAR(255);

    -- Cursor to fetch table names
    DECLARE table_cursor CURSOR FOR
        SELECT table_name
        FROM information_schema.tables
        WHERE table_schema = '数据库名' AND table_type = 'BASE TABLE';

    -- Cursor to fetch column names
    DECLARE column_cursor CURSOR FOR
        SELECT table_name, column_name
        FROM information_schema.columns
        WHERE table_schema = '数据库名';

    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

    OPEN table_cursor;

    table_loop: LOOP
        FETCH table_cursor INTO current_table_name;
        IF done = 1 THEN
            LEAVE table_loop;
        END IF;

        OPEN column_cursor;

        column_loop: LOOP
            FETCH column_cursor INTO current_table_name, current_column_name;
            IF done = 1 THEN
                LEAVE column_loop;
            END IF;

            SET @sql = CONCAT('UPDATE `', current_table_name, '` SET `', current_column_name, '` = REPLACE(`', current_column_name, '`, "https://test1.api.com/", "https://test2.api.com/")');
            PREPARE stmt FROM @sql;
            EXECUTE stmt;
            DEALLOCATE PREPARE stmt;
        END LOOP column_loop;

        CLOSE column_cursor;
    END LOOP table_loop;

    CLOSE table_cursor;

END
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇