GBase 8a 数据导入导出
目录
表结构导出工具gcdump
数据导出
数据导入
表结构导出工具gcdump
-A, --all-databases 导出所有用户数据库结构
-u, --user=name 连接数据库的数据库用户名
-p, --password[=name] 连接数据库的用户密码
-P, --port=# 连接数据库的端口
-B, --databases 导出指定的数据库结构
-f, --force 导出过程中忽略 sql 错误
--ignore-table=database.table 指定不要转储的表,该参数每次只能指定一个表,如果需要忽略多个表,使用多个参数指定。
-n, --no-create-db 不输出建库语句'CREATE DATABASE IF NOT EXISTS db_name;' 语句
-t, --no-create-info 不输出建表语句
-q, --quick 导出结果不缓存,直接输出
-Q, --quote-names 输出的表名和列名带引用符号(`)
-r, --result-file=name 导出结果输出到指定的文件中
-R, --routines 导出存储过程和函数
-W, --fixed-vc-name=name 指定导出的 VC 名字,一次只能导出一个 VC 的数据库对象,如果不指定该参数,该参数默认为 default vc
-X, --xml 导出文件格式为 xml
-I, --colId 导出表结构含 TID 和 UID,同 show full create table
数据导出
select * from test.outtable into outfile '/home/gbase/outtable.GZ' FIELDS TERMINATED BY '|' FIELDS ESCAPED BY '\\' optionally DOUBLE_ENCLOSED BY '\'' WRITEMODE BY overwrites;--如果在导出后 发现数据中包含转译符号\ 那么需要将转译符号置空 否则导入的数据会多一个\ select * from test.t1 into outfile '/home/gbase/t1.data4' FIELDS TERMINATED BY '|' FIELDS ESCAPED BY ''outfile '/home/gbase/outtable.GZ' 以gzip方式压缩
FIELDS TERMINATED BY '|' 分割符为 |
FIELDS ESCAPED BY '\\' 转译符为 \
optionally DOUBLE_ENCLOSED BY '\'' 包围符为 ' 只对字符串类型起作用
WRITEMODE BY overwrites 导出文件覆盖已有文件
gbase> create table outtable(no int,text varchar(10)); gbase> insert into test.outtable(no,text) values(1,'a''b'),(2,'a\\b'),(3,'a''\\b'); gbase> select * from outtable; +------+------+ | no | text | +------+------+ | 1 | a'b | | 2 | a\b | | 3 | a'\b | +------+------+ gbase> select * from test.outtable into outfile '/home/gbase/outtable.GZ' FIELDS TERMINATED BY '|' FIELDS ESCAPED BY '\\' optionally DOUBLE_ENCLOSED BY '\'' WRITEMODE BY overwrites; gbase> select * from test.outtable into outfile '/home/gbase/outtable.data' FIELDS TERMINATED BY '|' FIELDS ESCAPED BY '\\' optionally DOUBLE_ENCLOSED BY '\'' WRITEMODE BY overwrites; [gbase@hw-01 home]$ cd /home/gbase/outtable.data/ [gbase@hw-01 outtable.data]$ ll -rw------- 1 gbase gbase 29 Jan 18 11:06 outtable.data [gbase@hw-01 outtable.data]$ cat outtable.data 1|'a\'b' 2|'a\\b' 3|'a\'\\b'[gbase@hw-01 home]$ cd /home/gbase/outtable.GZ/ [gbase@hw-01 outtable.GZ]$ ll -rw------- 1 gbase gbase 39 Jan 18 11:05 outtable.GZ数据导入
如果有原始数据,记得先备份一下
备份表结构 [gbase@bogon ~]$ gcdump -ugbase -pgbase2011 -B test > /home/gbase/test_db_ddl.bak 备份数据 gbase> select * from test.audit_log_expressinto outfile '/home/gbase/audit_log_express.data' FIELDS TERMINATED BY '|' FIELDS ESCAPED BY '\\' optionally DOUBLE_ENCLOSED BY '\'' WRITEMODE BY overwrites;导入表结构
#这些是数据导出时的数据 不是备份的数据 [gbase@bogon ~]$ cd /home/gbase/ [gbase@bogon ~]$ ll total 8 -rw-r--r-- 1 gbase gbase 29 Jan 17 22:06 outtable.data -rw-r--r-- 1 gbase gbase 3546 Jan 17 21:52 test_db.sql gbase> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | performance_schema | | gbase | | gctmpdb | | gclusterdb | +--------------------+ gbase> \q[gbase@bogon ~]$ gccli -ugbase -pgbase2011 < /home/gbase/test_db.sql [gbase@bogon ~]$ gccli -uroot -pgbase> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | performance_schema | | gbase | | gctmpdb | | gclusterdb | | test | +--------------------+gbase> use test; gbase> show tables; +-------------------------+ | Tables_in_test | +-------------------------+ | audit_log_express | | import_audit_log_errors | | outtable | | t2 | | t5 | +-------------------------+导入数据
gbase> use test; gbase> select * from outtable; Empty set (Elapsed: 00:00:00.00)gbase> LOAD DATA INFILE 'file://192.168.61.173/home/gbase/outtable.data' INTO TABLE test.outtable data_format 3 fields terminated by '|';gbase> select * from outtable; +------+----------+ | no | text | +------+----------+ | 2 | 'a\\b' | | 1 | 'a\'b' | | 3 | 'a\'\\b' | +------+----------+ LOAD DATA INFILE 'file://192.168.61.173/home/gbase/outtable.GZ' INTO TABLE test.outtable data_format 3 fields terminated by '|' enclosed by '\'';trace 1 trace_path '/home/gbase/loader_logs' FILE_FORMAT GZIP;总结
以上是生活随笔为你收集整理的GBase 8a 数据导入导出的全部内容,希望文章能够帮你解决所遇到的问题。