导入导出命令

最近更新时间: 2024-06-12 15:06:00

INSERT 语句格式

###   只导出表结构和数据库创建语句:
./mydumper --host=xxx --port=xxx --user=xxx --password=xxx   --less-locking --chunk-filesize=1024 --ignore-sysdb=1 --threads=4   --outputdir=/data/backup/schema -B xxx -T xxx --no-data
举例:
./mydumper --host=10.0.1.9   --port=15002 --user=test1 --password=test1 --less-locking  --ignore-sysdb=1 --chunk-filesize=1024   --threads=4 --outputdir=/data/backup/schema -B test -T emp --no-data
说明:以上命令将test数据库上的emp表导出到/data/backup/schema目录下,导出文件test-schema-create.sql包含创建test数据库的DDL语句;导出文件test.emp-schema.sql包含创建emp表结构的DDL语句,不包含构造表数据的insert语句


 #### 只导出表数据    
./mydumper --host=xxx --port=xxx --user=xxx --password=xxx   --less-locking  --chunk-filesize=1024 --ignore-sysdb=1    --threads=4   --outputdir=/data/backup/data --complete-insert -B xxx -T xxx --no-schemas
举例:
./mydumper --host=10.0.1.9   --port=15002 --user=test1 --password=test1 --less-locking   --ignore-sysdb=1 --chunk-filesize=1024   --threads=4 --outputdir=/data/backup/data --complete-insert -B test -T emp   --no-schemas
说明:以上命令将test数据库上的emp表数据导出到/data/backup/data目录下,导出文件test.emp.sql包含构造emp表数据的insert语句


#### 同时导出表数据和表结构创建语句:
./mydumper   --host=xxx --port=xxx --user=xxx --password=xxx --less-locking  --chunk-filesize=1024 --ignore-sysdb=1  --threads=4 --outputdir=/data/backup/data_schema   --complete-insert -B xxx -T xxx
举例:
./mydumper --host=10.0.1.9   --port=15002 --user=test1 --password=test1 --less-locking   --ignore-sysdb=1 --chunk-filesize=1024   --threads=4 --outputdir=/data/backup/data_schema --complete-insert -B test -T   emp
说明:以上命令同时导出表数据和表结构创建语句,命令中避免带入--no-schemas、--no-data选项


### 只导入表结构    
./myloader --host=xxx --port=xxx --user=xxx --password=xxx   --directory=/data/backup/schema  --threads=4   --enable-binlog
举例:
./myloader   --host=10.0.1.9 --port=15002 --user=test1 --password=test1   --directory=/data/backup/schema --threads=4 --enable-binlog


### 只导入表数据    
./myloader --host=xxx --port=xxx --user=xxx --password=xxx   --directory=/data/backup/data   --threads=4 --enable-binlog
举例:
./myloader --host=10.0.1.9   --port=15002 --user=test1 --password=test1    --directory=/data/backup/data --threads=4 --enable-binlog

CSV 格式

###导出CSV格式的数据      
./mydumper --host=172.27.25.11 --port=15002 --user=test1 --password=test1 -B test  --tables-list customer --load-data --fields-terminated-by="," --fields-enclosed-by='"'   --lines-starting-by="---" --lines-terminated-by="\n" --fields-escaped-by='\' -o /data/backup/data/

说明:

CSV 格式的数据可以使用 loaddata工具 导入,详情参考《TDSQL MYSQL版 V10.3.20.x.x-Load_data工具使用说明》。