mysql 匯入匯出資料的方法總結
阿新 • • 發佈:2019-02-04
1. 以檔案形式匯出資料
https://dev.mysql.com/doc/refman/5.5/en/load-data.html
mysql -P port -u username -h ip -p password -e "use database ;query sql into outfile 'data.txt' FIELDS TERMINATED BY ',' enclosed by '\"' lines terminated by '\r\n'"
2. 以檔案形式匯入資料
mysql -P port -u username -h ip -p password -e "use database ;LOAD DATA INFILE 'data_file.txt' INTO TABLE table_name FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED by'\r\n'"
3. 匯出sql 檔案
mysqldump --single-transaction -P port -u username -h ip -p password database table > table.sql
4. 匯入sql檔案
mysql -P port -u username -h ip -p password -e database < table.sql.sql
或者
在mysql終端 source table.sql
5. 使用xtrabackup進行MySQL資料庫備份