GBase 8a 数据导入导出
目錄
表結構導出工具gcdump
數(shù)據(jù)導出
數(shù)據(jù)導入
表結構導出工具gcdump
-A, --all-databases 導出所有用戶數(shù)據(jù)庫結構
-u, --user=name 連接數(shù)據(jù)庫的數(shù)據(jù)庫用戶名
-p, --password[=name] 連接數(shù)據(jù)庫的用戶密碼
-P, --port=# 連接數(shù)據(jù)庫的端口
-B, --databases 導出指定的數(shù)據(jù)庫結構
-f, --force 導出過程中忽略 sql 錯誤
--ignore-table=database.table 指定不要轉儲的表,該參數(shù)每次只能指定一個表,如果需要忽略多個表,使用多個參數(shù)指定。
-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 導出存儲過程和函數(shù)
-W, --fixed-vc-name=name 指定導出的 VC 名字,一次只能導出一個 VC 的數(shù)據(jù)庫對象,如果不指定該參數(shù),該參數(shù)默認為 default vc?
-X, --xml 導出文件格式為 xml
-I, --colId 導出表結構含 TID 和 UID,同 show full create table
數(shù)據(jù)導出
select * from test.outtable into outfile '/home/gbase/outtable.GZ' FIELDS TERMINATED BY '|' FIELDS ESCAPED BY '\\' optionally DOUBLE_ENCLOSED BY '\'' WRITEMODE BY overwrites;--如果在導出后 發(fā)現(xiàn)數(shù)據(jù)中包含轉譯符號\ 那么需要將轉譯符號置空 否則導入的數(shù)據(jù)會多一個\ 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數(shù)據(jù)導入
如果有原始數(shù)據(jù),記得先備份一下
備份表結構 [gbase@bogon ~]$ gcdump -ugbase -pgbase2011 -B test > /home/gbase/test_db_ddl.bak 備份數(shù)據(jù) 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;?導入表結構
#這些是數(shù)據(jù)導出時的數(shù)據(jù) 不是備份的數(shù)據(jù) [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 | +-------------------------+導入數(shù)據(jù)
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 数据导入导出的全部內容,希望文章能夠幫你解決所遇到的問題。