mysql> SELECT replace(ifnull(last_name,''),'"','""'), replace(ifnull(first_name,''),'"','""'), replace(ifnull(last_name_kana,''),'"','""'), replace(ifnull(first_name_kana,''),'"','""'), IF(gender = 'F',"女","男"), replace(ifnull(birthday,''),'"','""'), replace(ifnull(address,''),'"','""'), replace(ifnull(tel,''),'"','""'), replace(ifnull(email,''),'"','""') FROM user WHERE prefecture_id is null INTO OUTFILE "/tmp/userlist.csv" FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"';