更新非常大的数据库中的字符串

时间:2019-03-24 17:52:02

标签: mysql sql mariadb

我正在尝试更新/替换MYSQL / MARIADB数据库上的几个字符串,我所需要的只是:

在所有数据库中为http://mysite.app更改所有这些确切的字符串https://mysite.app

问题在于此数据库非常大,正常替换可能会损坏服务器。

所以我想知道每时间或每秒钟或不会对服务器造成太大影响的东西吗?

1 个答案:

答案 0 :(得分:0)

您可以使用类似这样的查询来生成所有查询来做到这一点: 如果删除 GROUP_CONCAT( SEPARATOR'\ n'),则每个更新状态行将显示一行。

SELECT GROUP_CONCAT(
    CONCAT('UPDATE `',TABLE_SCHEMA,'`.`',TABLE_NAME,'` SET `',
        COLUMN_NAME,'` = REPLACE(',COLUMN_NAME,',\'http://mydomain\',\'https://mydomain\');')
        SEPARATOR '\n' ) as myquery
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE
    `TABLE_SCHEMA` not IN ('information_schema','performance_schema','mysql') -- excluded SCHEMAS
AND
    `DATA_TYPE` in ('varchar','char');

样本

    UPDATE `shopware`.`s_core_log` SET `value4` = REPLACE(value4,'http://mydomain','https://mydomain');
    UPDATE `shopware`.`s_core_engine_groups` SET `name` = REPLACE(name,'http://mydomain','https://mydomain');
    UPDATE `shopware`.`s_core_engine_groups` SET `label` = REPLACE(label,'http://mydomain','https://mydomain');
    UPDATE `shopware`.`s_core_engine_groups` SET `layout` = REPLACE(layout,'http://mydomain','https://mydomain');
    UPDATE `shopware`.`s_core_subscribes` SET `subscribe` = REPLACE(subscribe,'http://mydomain','https://mydomain');
....

    UPDATE `shopware`.`s_order_billingaddress` SET `additional_address_line1` = REPLACE(additional_address_line1,'http://mydomain','https://mydomain');
    UPDATE `shopware`.`s_order_billingaddress` SET `additional_address_line2` = REPLACE(additional_address_line2,'http://mydomain','https://mydomain');
    UPDATE `shopware`.`s_order_billingaddress` SET `title` = REPLACE(title,'http://mydomain','https://mydomain');