简体   繁体   中英

How can I mysqldump a table with SELECT statement?

I want to dump a table, but with masked emails, not as it is.

mysql -h <ip> -u <username> -P <port> -p --execute="
SELECT
    au.id,
    CASE WHEN (au.email NOT LIKE '%@abcd.com%' AND au.email NOT LIKE '%@abcd_test.com%') THEN CONCAT('user+', u.id, '@abcd_test.com') ELSE au.email END as email,
    au.user_id
    FROM <dbname>.<tablename> as au
    LEFT JOIN <dbname>.<tablename2> as u
" > ~/<tablename>.sql

I tried running this command, but it doesn't create a dump that can be imported.

Actually, there are couple other tables that have email columns that need to be masked similarly, and ideally I'd like to have a dump of the whole database with emails anonymized like this.

If that's not possible, I'd at least want to have a dump of a table with masked emails like the output from above shell command that can be imported separately into mysql database.

How can I dump a table with SELECT query? or can I import the output of the above command?

This is a production database, so I want to avoid creating a new table on this database or doing anything that can possibly mess up this database.

SELECT * INTO从OUTFILE 'dump.sql' table_name地方condition

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM