fields_in="email" fields_out="@usr" file="/tmp/ca.csv" table="table" echo "exporting $fields_in from $table" mysql -u in -N << eof select $fields_in from $table into outfile '$file' fields enclosed by '"' terminated by ';' escaped by '"' lines terminated by '\r\n'; eof [[ $? != 1 ]] || exit echo "importing $fields_out from $file" mysql -u out << eof load data infile '$file' ignore into table usrs fields enclosed by '"' terminated by ';' escaped by '"' lines terminated by '\r\n' ( $fields_out ) set id = @id, usr = @usr; eof [[ $? != 1 ]] || exit