在内核版本v1.0中,新增了gConsole组件,该组件基于命令行模式下实现了对数据库的“长会话”操作,在本地命令行模式下对数据库的管理更便捷 。目前已实现了20+的操作指令,接下来将详细介绍各指令使用。
1、启动gconsole
1.1 登录
bin/gconsole [-u <usr_name>]
缺失usr_name则会提示输入
# bin/gconsole
Enter user name: root
Enter password:
Gstore Console(gconsole), an interactive shell based utility to communicate with gStore repositories.
Gstore version: 1.0.0 Source distribution
Copyright (c) 2016, 2022, pkumod and/or its affiliates.
Welcome to the gStore Console.
Commands end with ;. Cross line input is allowed.
Comment start with #. Redirect (> and >>) is supported.
Type 'help;' for help. Type 'cancel;' to quit the current input statement.
gstore>
1.2 帮助
bin/gconsole --help
# bin/gconsole --help
Gstore Ver 1.0.0 for Linux on x86_64 (Source distribution)
Gstore Console(gconsole), an interactive shell based utility to communicate with gStore repositories.
Copyright (c) 2016, 2022, pkumod and/or its affiliates.
Usage: bin/gconsole [OPTIONS]
-?, --help Display this help and exit.
-u, --user username.
Supported command in gconsole: Type "?" or "help" in the console to see info of all commands.
For bug reports and suggestions, see https://github.com/pkumod/gStore
1.3 命令
以 ;
结尾,可以跨行支持 >
和>>
重定向输出支持单行注释, #
开始直到换行为注释内容支持命令补全、文件名补全、行编辑、历史命令 ctrl+C
放弃当前命令(结束执行或放弃编辑),ctrl+D
退出命令行进入gconsole需登录;符合当前[用户权限](# 权限说明)的命令才运行执行,以及仅显示符合当前用户权限的内容 7种权限: query
,load
,unload
,update
,backup
,restore
,export命令关键词不区分大小写,命令行option、数据库名、用户名、密码等区分大小写。命令关键词如下: 数据库操作: sparql
,create
,use
,drop
,show
,showdbs
,backup
,restore
,export
,pdb身份: flushpriv
,pusr
,setpswd查看配置信息: settings
,version权限管理: setpriv
,showusrs
,pusr用户管理: addusr
,delusr
,setpswd
,showusrs帮助和其他: quit
,help/?
,pwd
,clear
2、数据库操作
2.1 创建数据库
create <database_name> [<nt_file_path>]
从nt_file_path读取 .nt
文件并创建数据库database_name,或者创建空数据库,当前用户被赋予对database_name的[全部权限](# 权限说明)<database_name>:数据库名不能是 system<nt_file_path>:文件路径
gstore> create eg my_test_data/eg_rdf.nt;
... (this is build database process output, omitted in this document)
Database eg created successfully.
2.2 删除数据库
drop <database_name>
不能删除当前数据库 <database_name>:数据库名称,仅能指定为当前用户拥有[全部权限](# 权限说明)的数据库
gstore> drop <database_name>;
2.3 指定/切换当前数据库
use <database_name>
指定/切换当前数据库,把之前的当前数据库从内存卸载(如果有的化)并把指定的当前数据库加载到内存
目标数据库需要已经创建
<database_name>:数据库名称,仅能指定为当前用户拥有[load和unload权限](# 权限说明)的数据库
gstore> use mytest;
... (this is load process output, omitted in this document)
Current database switch to mytest successfully.
2.4 查询/更新当前数据库
在当前数据库上进行sparql查询 需要先 use <database_name>
指定当前数据库
2.4.1 console输入sparql
gstore> # show all in db
-> SELECT ?x ?y ?z
-> WHERE{
-> ?x ?y ?z. # comment
-> } ;
... (this is query process output, omitted in this document)
final result is :
?x ?y ?z
<root> <has_password> "123456"
<system> <built_by> <root>
<CoreVersion> <value> "1.0.0"
query database successfully, Used 15 ms
支持重定向举例(所有命令均支持重定向输出)
gstore> # support redirect
-> SELECT ?x ?y ?z
-> WHERE{
-> ?x ?y ?z.
-> } > my_test_data/output ;
Redirect output to file: my_test_data/output
2.4.2 sparql <sparql_file>
指定sparql文件,文件中包含多条sparql语句需要以
;
间隔,最后;
可有可不有文件内容支持单行注释,
#
开头
gstore> sparql query.sparql ;
... (this is query process output, omitted in this document)
final result is :
?x ?y ?z
<root> <has_password> "123456"
<system> <built_by> <root>
<CoreVersion> <value> "1.0.0"
query database successfully, Used 15 ms
query.sparql内容举例:
# comment
SELECT ?t1_time
WHERE
{
# comment
<t1><built_time>?t1_time. # comment
};
# comment
SELECT ?t2_time
WHERE
{
# comment
<t2><built_time>?t2_time. # comment
};
2.5 显示数据库信息
show [<database_name>] [-n <displayed_triple_num>]
显示meta信息和前displayed_triple_num行三元组(默认显示前10行三元组) <database_name>:数据库名称,不指定database_name则显示当前数据库的信息 -n <displayed_triple_num>:显示行数
gstore> show eg;
... (this is load and query process output, omitted in this document)
===================================================
Name: eg
TripleNum: 15
EntityNum: 6
LiteralNum: 0
SubNum: 3
PreNum: 3
===================================================
<Alice> <关注> <Bob>
<Bob> <关注> <Alice>
<Carol> <关注> <Bob>
<Dave> <关注> <Alice>
<Dave> <关注> <Eve>
<Alice> <喜欢> <Bob>
<Bob> <喜欢> <Eve>
<Eve> <喜欢> <Carol>
<Carol> <喜欢> <Bob>
<Francis> <喜欢> <Carol>
2.6 查看所有数据库
showdbs
仅显示当前用户有查询权限的数据库
gstore> showdbs;
"database" "creater" status"
<system> <root>
<eg> <yuanzhiqiu> "already_built"
2.7 显示当前数据库名
pdb
gstore> pdb;
eg
2.8 备份当前数据库
backup [<backup_folder>]
<backup_folder>指定备份的路径
gstore> backup;
... (this is backup process output, omitted in this document)
Database eg backup successfully.
gstore> backup back;
... (this is backup process output, omitted in this document)
Database eg backup successfully.
2.9 导出当前数据库
export <file_path>
<file_path>:指定导出的路径
gstore> export eg.nt;
Database eg export successfully.
2.10 恢复数据库
restore <database_name> <backup_path>
<database_name>:数据库名称 <backup_path>:备份文件路径
gstore> restore eg backups/eg.db_220929114732/
... (this is restore process output, omitted in this document)
Database eg restore successfully.
3、身份
3.1 刷新权限
flushpriv
读取db刷新当前用户权限
gstore> flushpriv;
Privilige Flushed for current user successfully.
3.2 显示当前用户名和权限
pusr [<database_name>]
pusr
显示当前用户名pusr <database_name>
显示当前用户名和当前用户在<database_name>上的权限
gstore> pusr;
usrname: yuanzhiqiu
gstore> pusr eg;
usrname: yuanzhiqiu
privilege on eg: query load unload update backup restore export
3.3 修改当前用户密码
setpswd
需要输入密码验证身份
gstore> setpswd;
Enter old password:
Enter new password:
Enter new password again:
Not Matched.
Enter new password:
Enter new password again:
Password set successfully.
4、查看配置信息
4.1 查看配置
settings [<conf_name>]
settings显示所有配置信息
gstore> settings;
Settings:
thread_num 30
... (this is other settings, omitted in this document)
You can Edit configuration file to change settings: conf.ini
<conf_name>:显示指定名称conf_name的配置信息
gstore> settings ip_deny_path;
"ipDeny.config"
You can Edit configuration file to change settings: conf.ini
4.2 查看版本
version
输出当前本版信息
gstore> version;
Gstore version: 1.0 Source distribution
Copyright (c) 2016, 2022, pkumod and/or its affiliates.
5、权限管理
权限管理相关命令只有系统用户有权限执行,权限说明如下:
权限:某用户对某数据库所拥有的权限
7种权限:
query
,load
,unload
,update
,backup
,restore
,export[1]query [2]load [3]unload [4]update [5]backup [6]restore [7]export7种权限都有称为拥有全部权限
系统用户拥有对全部数据库的全部权限(系统用户名在conf.ini和system.db中定义)
5.1 设置用户权限
setpriv <usrname> <database_name>
需要输入密码验证root身份 :被设置的用户名 <database_name>:数据库名称
gstore> setpriv zero eg;
Enter your password:
[1]query [2]load [3]unload [4]update [5]backup [6]restore [7]export [8]all
Enter privilege number to assign separated by whitespace:
1 2 3
[will set priv:]00001110
Privilege set successfully.
5.2 查看用户权限
pusr <database_name> <usrname>
<database_name>:数据库名称 :用户名
gstore> pusr eg yuanzhiqiu;
privilege on eg: query load unload update backup restore export
5.3 查看所有用户和权限
showusrs
显示有哪些用户,并显示每个用户的数据库权限(仅显示非root用户的;仅显示该用户有has_xxx_priv的数据库)
格式为:
usrname
------------------------
privilege on databases
gstore> showusrs;
root
----
all privilege on all db
yuanzhiqiu
----------
eg: query load unload update backup restore export
mytest1: query load unload
zero
----
mytest2: query load unload
6、用户管理
用户管理相关命令只有系统用户有权限执行
6.1 添加用户
addusr <usrname>
需要输入密码验证root身份 :新用户名
gstore> addusr uki;
Enter your password:
Enter password for new user: hello
Add usr uki successfully.
6.2 删除用户
delusr <usrname>
需要输入密码验证root身份 :待删除的用户名
gstore> delusr cat;
Enter your password:
Del usr cat successfully.
6.3 重置密码
setpswd <usrname>
需要输入密码验证root身份 :用户名
gstore> setpswd zero;
Enter your password:
Enter new password:
Enter new password again:
Password set successfully.
6.4 查看所有用户
showusrs
gstore> showusrs;
root
----
all privilege on all db
lubm
----
7、帮助和其他
7.1 结束/取消当前命令
ctrl+C
结束当前正在执行的命令
...(executing some cmd) (ctrl+C here)
gstore>
或放弃当前在输入的命令
gstore> SELECT ?x ?y ?z
-> WHERE{ (ctrl+C here)
gstore>
7.2 退出
quit
/ctrl+D
如果当前数据库没有卸载则会从内存中卸载
gstore> quit;
[xxx@xxx xxx]#
gstore> (ctrl+D here)
[xxx@xxx xxx]#
7.3 帮助
help [edit/usage/<command>]
help
显示所有命令帮助信息
gstore> help;
Gstore Console(gconsole), an interactive shell based utility to communicate with gStore repositories.
For information about gStore products and services, visit:
http://www.gstore.cn/
For developer information, including the gStore Reference Manual, visit:
http://www.gstore.cn/pcsite/index.html#/documentation
Commands end with ;. Cross line input is allowed.
Comment start with #.
Type 'cancel;' to quit the current input statement.
List of all gconsole commands:
sparql Answer SPARQL query(s) in file.
create Build a database from a dataset or create
...(this is help msg for other commands, omitted in this document)
Other help arg:
edit Display line editing shortcut keys supported by gconsole.
usage Display all commands as well as their usage.
help edit
显示GNU readline的行编辑快捷键操作
gstore> help edit;
Frequently used GNU Readline shortcuts:
CTRL-a move cursor to the beginning of line
CTRL-e move cursor to the end of line
CTRL-d delete a character
CTRL-f move cursor forward (right arrow)
CTRL-b move cursor backward (left arrow)
CTRL-p previous line, previous command in history (up arrow)
CTRL-n next line, next command in history (down arrow)
CTRL-k kill the line after the cursor, add to clipboard
CTRL-u kill the line before the cursor, add to clipboard
CTRL-y paste from the clipboard
ALT-b move cursor back one word
ALT-f move cursor forward one word
For more about GNU Readline shortcuts, see https://en.wikipedia.org/wiki/GNU_Readline#Emacs_keyboard_shortcuts
help usage
显示所有命令的描述和usage
gstore> help usage;
List of all gconsole commands:
Note that all text commands must be end with ';' but need not be in one line.
sparql Answer SPARQL query(s) in file.
sparql <; separated SPARQL file>;
create Build a database from a dataset or create an empty database.
create <database_name> [<nt_file_path>];
...(this is help msg for other commands, omitted in this document)
help <command>
显示的帮助信息
gstore> help use;
use Set current database.
use <database_name>;
7.4 清屏
gstore> clear;
7.5 查看当前工作路径
gstore> pwd;
/<path_to_gstore>/gstore
8 查看gstore内核版本
bin/gconsole --version
Gstore version: 1.0 Source distribution
Copyright (c) 2016, 2022, pkumod and/or its affiliates.
文章转载自图谱学苑,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




