南大通用数据库-Gbase-8a-学习-34-gcdump(导出数据库对象定义)

目录

一、测试环境

二、介绍

三、命令帮助

 四、参数介绍

1、--print-defaults

(1)含义

(2)例子

2、--connect_timeout

(1)含义

(2)例子

3、-A, --all-databases

(1)含义

(2)例子

4、-s, --system-databases

(1)含义

(2)例子

5、-U, --user-databases

(1)含义

(2)例子

6、--default-character-set

(1)含义

(2)例子

7、--character-sets-dir

(1)含义

8、-i, --comments 

(1)含义

(2)例子

9、-B, --databases

(1)含义

(2)例子

10、-f, --force

(1)含义

(2)例子

11、-h, --host

(1)含义

(2)例子

12、--ignore-table

(1)含义

(2)例子

13、--log-error

(1)含义

(2)例子

14、-n, --no-create-db

(1)含义

(2)例子

15、-t, --no-create-info

(1)含义

(2)例子

16、-p, --password

(1)含义

(2)例子

17、-P, --port

(1)含义

(2)例子

18、--protocol

(1)含义

(2)例子

19、-q, --quick

(1)含义

(2)例子

20、-Q, --quote-names

(1)含义

(2)例子

21、--replace

(1)含义

22、-r, --result-file

(1)含义

(2)例子

23、-R, --routines

(1)含义

(2)例子

24、-F, --file-path

(1)含义

(2)例子

25、--set-charset

(1)含义

(2)例子

26、-O, --set-variable

(1)含义

27、-I, --colId

(1)含义

(2)例子

28、-S, --socket

(1)含义

29、-u, --user

(1)含义

(2)例子

30、-V, --version

(1)含义

(2)例子


 


 

一、测试环境

名称
CPUIntel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
操作系统CentOS Linux release 7.9.2009 (Core)
内存3G
逻辑核数2
Gbase8a版本8.6.2-R43

 

二、介绍

gcdump工具支持导出表、自定义函数、自定义存储过程、python外部函数等数据库对象,但不支持导出数据,需要导出数据的小伙伴可以之前写的文章《南大通用数据库-Gbase-8a-学习-14-LOAD加载数据

 

三、命令帮助

[gbase@czg2 Select]$ gcdump --help
gcdump ver 8.6.2-R43.34.27468a27, for redhat-linux (x86_64)
Dumping definition and data gbase database or table
Usage: gcdump [OPTIONS] database [tables]
OR     gcdump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR     gcdump [OPTIONS] --all-databases [OPTIONS]
The following groups are read: gbasedump client
The following options may be given as the first argument:
--print-defaults    Print the program argument list and exit
--no-defaults       Don't read default options from any options file
--defaults-file=#   Only read default options from the given file #
--defaults-extra-file=# Read this file after the global files are read
  --connect_timeout=# Number of seconds before connection timeout.
  -A, --all-databases Dump all the databases. This will be same as --databases
                      with all databases selected.
  -s, --system-databases 
                      Dump system databases. 
  -U, --user-databases 
                      Dump all fixed user databases. 
  --default-character-set=name 
                      Set the default character set.
  --character-sets-dir=name 
                      Directory where character sets are.
  -i, --comments      Write additional information.
  --net_buffer_length=# 
  -B, --databases     To dump several databases. Note the difference in usage;
                      In this case no tables are given. All name arguments are
                      regarded as databasenames. 'USE db_name;' will be
                      included in the output.
  -f, --force         Continue even if we get an sql-error.
  -?, --help          Display this help message and exit.
  -h, --host=name     Connect to host.
  --ignore-table=name Do not dump the specified table. To specify more than one
                      table to ignore, use the directive multiple times, once
                      for each table.  Each table must be specified with both
                      database and table names, e.g.
                      --ignore-table=database.table
  --log-error[=name]  Append warnings and errors to given file.
  --max_allowed_packet=# 
  -n, --no-create-db  'CREATE DATABASE IF NOT EXISTS db_name;' will not be put
                      in the output. The above line will be added otherwise, if
                      --databases or --all-databases option was given.}.
  -t, --no-create-info 
                      Don't write table creation info.
  -p, --password[=name] 
                      Password to use when connecting to server. If password is
                      not given it's solicited on the tty.
  -P, --port=#        Port number to use for connection.
  --protocol=name     The protocol of connection (tcp,socket,pipe,memory).
  -q, --quick         Don't buffer query, dump directly to stdout.
  -Q, --quote-names   Quote table and column names with backticks (`).
  --replace           Use REPLACE INTO instead of INSERT INTO.
  -r, --result-file=name 
                      Direct output to a given file. This option should be used
                      in MSDOS, because it prevents new line '\n' from being
                      converted to '\r\n' (carriage return + line feed).
  -R, --routines      Dump stored routines (functions and procedures).
  -F, --file-path=name 
                      For local temp file
  --set-charset       Add 'SET NAMES default_character_set' to the output.
                      Enabled by default; suppress with --skip-set-charset.
  -O, --set-variable=name 
                      Change the value of a variable. Please note that this
                      option is deprecated; you can set variables directly with
                      --variable-name=value.
  -S, --socket=name   Socket file to use for connection.
  -u, --user=name     User for login if not current user.
  -V, --version       Output version information and exit.
  -I, --colId         Show TID and COLUMN_IDS.

Variables (--variable-name=value)
and boolean options {FALSE|TRUE}  Value (after reading options)
--------------------------------- -----------------------------
connect_timeout                   43200
all-databases                     FALSE
system-databases                  FALSE
user-databases                    FALSE
default-character-set             utf8
character-sets-dir                (No default value)
comments                          TRUE
net_buffer_length                 1046528
databases                         FALSE
force                             FALSE
host                              (No default value)
max_allowed_packet                67108864
no-create-db                      FALSE
no-create-info                    FALSE
port                              5258
quick                             TRUE
quote-names                       TRUE
replace                           FALSE
routines                          FALSE
set-charset                       TRUE
socket                            /tmp/gcluster_5258.sock
user                              (No default value)

 

 四、参数介绍

 

1、--print-defaults

 

(1)含义

打印程序参数列表并退出。


(2)例子

[gbase@czg2 Select]$ gcdump --print-defaults
gcdump would have been started with the following arguments:
--port=5258 --socket=/tmp/gcluster_5258.sock --connect_timeout=43200 --max_allowed_packet=64M

 

2、--connect_timeout

 

(1)含义

连接超时前的秒数。


(2)例子

[gbase@czg2 ~]$ gcdump  --connect_timeout=10 -h 192.168.142.12 -U zxj > gcdump_2023_04_25.txt
[gbase@czg2 ~]$ ll
总用量 84996
-rw-rw-rw- 1 gbase gbase       36 3月  31 16:33 ALLDbVoidRate.txt
-rw-rw-r-- 1 gbase gbase     9958 4月  25 09:38 gcdump_2023_04_25.txt
-rw-r--r-- 1 root  root  87013244 8月  23 2022 gcluster_backup_20220823111929.tar.bz2
drwxr-xr-x 6 gbase gbase      154 11月 16 17:51 gcmonitor_agent
drwxr-xr-x 6 gbase gbase      194 11月 16 17:33 gcmonitor_center
-rw-rw-r-- 1 gbase gbase      152 3月  29 11:11 Sql.txt
drwxrwxr-x 3 gbase gbase       28 9月  21 2022 tablespace_10m

 

3、-A, --all-databases

 

(1)含义

转储所有数据库,但不包含系统库。这将与--databases相同选择了所有数据库。


(2)例子

[gbase@czg2 ~]$ gcdump  --connect_timeout=10 -h 192.168.142.12 -A > gcdump_2023_04_25.txt
2023-04-25 09:41:10.831  gcdump: /*warning: information_schema is system db, don't hold export!*/ 

2023-04-25 09:41:10.831  gcdump: /*warning: performance_schema is system db, don't hold export!*/ 

2023-04-25 09:41:10.941  gcdump: /*warning: gbase is system db, don't hold export!*/ 

2023-04-25 09:41:10.941  gcdump: /*warning: gclusterdb is system db, don't hold export!*/ 

2023-04-25 09:41:10.941  gcdump: /*warning: gctmpdb is system db, don't hold export!*/ 

 

4、-s, --system-databases

 

(1)含义

导出系统库,会有报错提示:gbase.drop_temp_table不支持任何操作。后续我再摸索一下。


(2)例子

[gbase@czg2 ~]$ gcdump  --connect_timeout=10 -h 192.168.142.12 -f -s > gcdump_2023_04_25.txt
2023-04-25 09:45:40.725  gcdump: Couldn't execute 'SHOW CREATE EVENT `drop_temp_table`': (GBA-01-600) Gbase internal error: gbase.drop_temp_table is system fixed event,not support any operator (1732)

[gbase@czg2 ~]$ tail -100 gcdump_2023_04_25.txt 

--
-- Dumping events for database 'gbase'
--

 

5、-U, --user-databases

 

(1)含义

转储所有固定用户数据库。

也就是把所有用户自建库的对象定义都导出。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -U > gcdump_2023_04_25.txt

 

6、--default-character-set

 

(1)含义

设置导出文件的默认字符集。


(2)例子

测试utf8字符集

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -U --default-character-set=utf8 > gcdump_2023_04_25.txt

 6ae69c71fe5f41e0952ca163fb6b33a5.png

 测试gbk字符集

[gbase@czg2 gcdump -h 192.168.142.12 -U --default-character-set=gbk > gcdump_2023_04_25_gbk.txt

 529d68779f61ab782228eb7fcbc813bd.png

 

7、--character-sets-dir

 

(1)含义

安装字符集的目录。具体用法后续摸索一下。

 

8、-i, --comments 

 

(1)含义

编写附加信息。

加与不加区别不大。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B zxj -i > gcdump_2023_04_25_gbk.txt

 

9、-B, --databases

 

(1)含义

转储多个数据库。注意用法上的差异;

在这种情况下,没有给出表格。所有名称参数都是被视为数据库名字。'USE db_name;'将包括在输出中。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B zxj czg -i > gcdump_2023_04_25_gbk.txt

d53d85e9e63879f50d44b6ee9a9948c1.png

 6d20607dde4510f77192d2e4fe8e50e0.png

 

10、-f, --force

 

(1)含义

即使出现sql错误,也要继续。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B zxj czg -f > gcdump_2023_04_25_gbk.txt

 

11、-h, --host

 

(1)含义

连接的主机IP。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B zxj czg -f > gcdump_2023_04_25_gbk.txt

 

12、--ignore-table

 

(1)含义

不要转储指定的表。指定多个要忽略的表,多次使用该指令,一次一个表。每个表都必须同时指定数据库和表名。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B zxj czg -f > gcdump_2023_04_25_gbk.txt

[gbase@czg2 ~]$ cat gcdump_2023_04_25_gbk.txt |grep testtab
DROP TABLE IF EXISTS `testtab`;
CREATE TABLE `testtab` (
  KEY `testtab_index_a` (`a`) USING HASH GLOBAL,
  KEY `testtab_index_c` (`c`) USING HASH GLOBAL
DROP TABLE IF EXISTS `testtab_copy`;
CREATE TABLE `testtab_copy` (
  KEY `testtab_c_index_a` (`a`) USING HASH GLOBAL
DROP TABLE IF EXISTS `testtab`;
CREATE TABLE `testtab` (
  KEY `testtab_index_c` (`c`) USING HASH GLOBAL
DROP TABLE IF EXISTS `testtab_copy`;
CREATE TABLE `testtab_copy` (

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B zxj czg --ignore-table=czg.testtab --ignore-table=czg.testtab_copy --ignore-table=zxj.testtab --ignore-table=zxj.testtab_copy -f > gcdump_2023_04_25_gbk.txt

[gbase@czg2 ~]$ cat gcdump_2023_04_25_gbk.txt |grep testtab

 

13、--log-error

 

(1)含义

将警告和错误附加到给定的文件中。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B zxj --log-error=LogError.log > gcdump_2023_04_25_gbk.txt

[gbase@czg2 ~]$ ll
总用量 84988
-rw-rw-rw- 1 gbase gbase       36 3月  31 16:33 ALLDbVoidRate.txt
-rw-rw-r-- 1 gbase gbase     4089 4月  25 10:41 gcdump_2023_04_25_gbk.txt
-rw-r--r-- 1 root  root  87013244 8月  23 2022 gcluster_backup_20220823111929.tar.bz2
drwxr-xr-x 6 gbase gbase      154 11月 16 17:51 gcmonitor_agent
drwxr-xr-x 6 gbase gbase      194 11月 16 17:33 gcmonitor_center
-rw-rw-r-- 1 gbase gbase        0 4月  25 10:41 LogError.log
-rw-rw-r-- 1 gbase gbase      152 3月  29 11:11 Sql.txt
drwxrwxr-x 3 gbase gbase       28 9月  21 2022 tablespace_10m

 

14、-n, --no-create-db

 

(1)含义

'CREATE DATABASE IF NOT EXISTS db_name;'不会被放置在输出中。如果--databases或--all databases选项给出。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B zxj > gcdump_2023_04_25_gbk.txt

[gbase@czg2 ~]$ cat gcdump_2023_04_25_gbk.txt |grep 'CREATE DATABASE'
CREATE DATABASE  IF NOT EXISTS `zxj` DEFAULT CHARACTER SET utf8;

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B zxj -n > gcdump_2023_04_25_gbk.txt

[gbase@czg2 ~]$ cat gcdump_2023_04_25_gbk.txt |grep 'CREATE DATABASE'

 

15、-t, --no-create-info

 

(1)含义

不要写入表创建信息。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B zxj -t > gcdump_2023_04_25_gbk.txt
[gbase@czg2 ~]$ cat gcdump_2023_04_25_gbk.txt 

DROP DATABASE IF EXISTS `zxj`;

CREATE DATABASE  IF NOT EXISTS `zxj` DEFAULT CHARACTER SET utf8;

USE `zxj`;

--
-- Dumping events for database 'zxj'
--

USE `zxj`;

 

16、-p, --password

 

(1)含义

连接到服务器时要使用的密码。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B zxj -u czg > gcdump_2023_04_25_gbk.txt
2023-04-25 10:51:46.901  gcdump: Got error: 1045: Access denied for user 'czg'@'192.168.142.12' (using password: NO) when trying to connect

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B zxj -u czg -pqwer1234 > gcdump_2023_04_25_gbk.txt

 

17、-P, --port

 

(1)含义

连接数据库的端口号。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B zxj -u czg -pqwer1234 -P 5258 > gcdump_2023_04_25_gbk.txt

 

18、--protocol

 

(1)含义

连接的协议(tcp,socket,pipe,memory)(tcp、套接字、管道、内存)。

套接字、管道、内存没有测试过。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B zxj --protocol=tcp > gcdump_2023_04_25_gbk.txt

 

19、-q, --quick

 

(1)含义

不缓冲查询,直接转储到stdout。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B zxj -q > gcdump_2023_04_25_gbk.txt

 

20、-Q, --quote-names

 

(1)含义

用反引号(`)引用表名和列名。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B zxj -Q > gcdump_2023_04_25_gbk.txt

[gbase@czg2 ~]$ tail -10 gcdump_2023_04_25_gbk.txt 
  `a` int(11) DEFAULT NULL,
  `b` double DEFAULT NULL,
  `c` varchar(100) DEFAULT NULL,
  `d` text,
  `e` blob,
  `f` longblob,
  `g` date DEFAULT NULL,
  `h` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  KEY `testtab_c_index_a` (`a`) USING HASH GLOBAL
) ENGINE=EXPRESS DEFAULT CHARSET=utf8 TABLESPACE='sys_tablespace';

 

21、--replace

 

(1)含义

使用REPLACE INTO而不是INSERT INTO。

Gbase不支持导出数据,所以可以忽略这个参数。

 

22、-r, --result-file

 

(1)含义

直接输出到给定的文件。应使用此选项在MSDOS中,因为它阻止新行“\n”已转换为“\r\n”(回车+换行)。

此参数不生效,会生成一个空文件。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B zxj -r gcdump_2023_04_25_gbk.txt

 

23、-R, --routines

 

(1)含义

导出自定义存储过程和函数。

此参数不生效,会生成一个空文件。

-B导出一个库时,加不加-R都导出自定义存储过程和函数。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -R > gcdump_2023_04_25_gbk.txt

 

24、-F, --file-path

 

(1)含义

生成本地临时文件


(2)例子

[gbase@czg2 ~]$ mkdir gcdump_file

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B czg -F gcdump_file

[gbase@czg2 ~]$ ll gcdump_file/czg/
总用量 8
-rw-rw-r-- 1 gbase gbase 4665 4月  25 11:13 create_db.sql
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_a
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_alldbvoidrate
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_b
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_czg
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_czg_test
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_d_admin_kpi_code
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_hash_tb_like
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_moon
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_moon_copy
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_sun
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_test
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_test_12_05
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_test20230302
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_testtab
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_testtab_copy
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_test_table
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_test_table_1
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_test_table_2
drwxrwxr-x 3 gbase gbase   18 4月  25 11:13 t_test_table_3

[gbase@czg2 ~]$ cat gcdump_file/czg/t_sun/meta/create_tb.sql 
use czg;
DROP TABLE IF EXISTS `sun`;
CREATE TABLE `sun` (
  `a` int(11) DEFAULT NULL
) ENGINE=EXPRESS DEFAULT CHARSET=utf8 TABLESPACE='sys_tablespace';

 

25、--set-charset

 

(1)含义

添加'SET NAMES default_character_set'到输出中。

默认启用;使用--skip-set-charset抑制。

测试不生效。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B czg --set-charset > gcdump_2023_04_25_gbk.txt
[gbase@czg2 ~]$ cat gcdump_2023_04_25_gbk.txt |grep 'SET NAMES'

 

26、-O, --set-variable

 

(1)含义

更改变量的值。请注意

选项已弃用;可以使用直接设置变量--variable-name=value。

 

27、-I, --colId

 

(1)含义

展示TID and COLUMN_IDS。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B czg -I > gcdump_2023_04_25_gbk.txt

[gbase@czg2 ~]$ tail -10 gcdump_2023_04_25_gbk.txt 
CREATE TABLE `testtab_copy` (
  `a` int(11) DEFAULT NULL,
  `b` double DEFAULT NULL,
  `c` varchar(100) DEFAULT NULL,
  `d` text,
  `e` blob,
  `f` longblob,
  `g` date DEFAULT NULL,
  `h` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=EXPRESS TID(6147) UID(1) DEFAULT CHARSET=utf8 TABLESPACE='sys_tablespace' COLUMN_IDS(0, 1, 2, 3, 4, 5, 6, 7);

 

28、-S, --socket

 

(1)含义

用于连接的套接字文件。

 

29、-u, --user

 

(1)含义

用于登录的用户(如果不是当前用户)。


(2)例子

[gbase@czg2 ~]$ gcdump -h 192.168.142.12 -B czg -u czg -pqwer1234 > gcdump_2023_04_25_gbk.txt

 

30、-V, --version

 

(1)含义

输出版本信息,然后退出。


(2)例子

[gbase@czg2 ~]$ gcdump -V
gcdump ver 8.6.2-R43.34.27468a27, for redhat-linux (x86_64)

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值