Skip to content

Instantly share code, notes, and snippets.

@mttjohnson
Created January 9, 2017 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mttjohnson/7b05110a7d72f1d29f2ad58d94873192 to your computer and use it in GitHub Desktop.
Save mttjohnson/7b05110a7d72f1d29f2ad58d94873192 to your computer and use it in GitHub Desktop.
email cleanup sql
' replace mydomainnamehere.com
' replace db_name_here
use information_schema;
SET SESSION group_concat_max_len=10000000;
select
group_concat(
concat('UPDATE `',`table_name`,'` SET `',`column_name`,'` = REPLACE(`',`column_name`,'`, SUBSTRING(`',`column_name`,'`, LOCATE(''@'', `',`column_name`,'`)), CONCAT(''+'', SUBSTRING(MD5(SUBSTRING(`',`column_name`,'`, LOCATE(''@'', `',`column_name`,'`))) FROM 1 FOR 6), ''@example.com'')) WHERE `',`column_name`,'` NOT LIKE ''%@mydomainnamehere.com'';') SEPARATOR '\n\n') as q
from `columns` as c
where
table_schema = 'db_name_here' /* UPDATE DATABASE NAME */
and (
(`column_name` like '%email%' and `data_type` in ('varchar', 'text'))
or (`table_name` like '%core_config_data' and `column_name` = 'value')
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment