公司突然要求匯出某個table的某個column
mysqldump又不支援只輸出一個欄位,
山不轉路轉, 先將要輸出的欄位生成新表在dump即可~
# 假如資料表已存在刪除
DROP TABLE IF EXISTS `_database_`.`_new_table_`;
# 新增資料表
CREATE TABLE `_database_`.`_new_table_`
SELECT `_column_`
FROM `_database_`.`_src_table_`
WHERE ...
# 將資料dump到/tmp底下, 因為tmp寫入不受權限限制
mysqldump -u root -p -t -T/tmp --fields-enclosed-by=\" --fields-terminated-by=, --databases _databases_ --tables _new_table_;
匯出後會在/tmp底下找到2個檔
_new_table_.sql
_new_table_.txt