创建表语句
create 'Student','StuInfo','Grades' Student表名 StuInfo、Grades 字段名
注意在 HBase Shell 语法中,所有字符串参数都必须包含在单引号中,且区分大小写,如 Student 和 student 代表两个不同的表
另外,在上条命令中没有对列族参数进行定义,因此使用的都是默认参数,如果建表时要设置列族的参数,参考以下方式:
create 'Student', {NAME => 'Stulnfo', VERSIONS => 3}, {NAME =>'Grades', BLOCKCACHE => true}
大括号内是对列族的定义,NAME、VERSION 和 BLOCKCACHE 是参数名,无须使用单引号,符号=>表示将后面的值赋给指定参数。例如,VERSIONS => 3是指此单元格内的数据可以保留最近的 3 个版本,BLOCKCACHE => true指允许读取数据时进行缓存
list 查看表名集合
desc 表名 查看表的结构
插入语句: put 'Student','01','Stulnfo','2015001111'
Student代表表名
01 行号
Stulnfo 列名
2015001111 字段对应的值
scan 'Student', {STARTROW => '01', ENDROW => 'row3'} 查询表记录列表
STARTROW 代表固定的默认列名称
语法:get <table>,<rowkey>,[<family:column>,....]
hbase(main):008:0> get 'User', 'row2'
COLUMN CELL
info:age timestamp=1502368069926, value=18
1 row(s) in 0.0280 seconds
hbase(main):028:0> get 'User', 'row3', 'info:sex'
COLUMN CELL
info:sex timestamp=1502368093636, value=man
hbase(main):036:0> get 'User', 'row1', {COLUMN => 'info:name'}
COLUMN CELL
info:name timestamp=1502368030841, value=xiaoming
1 row(s) in 0.0120 seconds
4. 统计表记录数
语法:count <table>, {INTERVAL => intervalNum, CACHE => cacheNum}
INTERVAL设置多少行显示一次及对应的rowkey,默认1000;CACHE每次去取的缓存区大小,默认是10,调整该参数可提高查询速度
hbase(main):020:0> count 'User'
3 row(s) in 0.0360 seconds
=> 3
删除列
hbase(main):008:0> delete 'User', 'row1', 'info:age'
0 row(s) in 0.0290 seconds
删除所有行
hbase(main):014:0> deleteall 'User', 'row2'
0 row(s) in 0.0090 seconds
删除表中所有数据
hbase(main):016:0> truncate 'User'
Truncating 'User' table (it may take a while):
- Disabling table...
- Truncating table...
0 row(s) in 3.6610 seconds
删除前,必须先disable
hbase(main):030:0> drop 'TEST.USER'
ERROR: Table TEST.USER is enabled. Disable it first.
Here is some help for this command:
Drop the named table. Table must first be disabled:
hbase> drop 't1'
hbase> drop 'ns1:t1'
hbase(main):031:0> disable 'TEST.USER'
0 row(s) in 2.2640 seconds
hbase(main):033:0> drop 'TEST.USER'
0 row(s) in 1.2490 seconds
hbase(main):034:0> list
TABLE
SYSTEM.CATALOG
SYSTEM.FUNCTION
SYSTEM.SEQUENCE
SYSTEM.STATS
User
5 row(s) in 0.0080 seconds
=> ["SYSTEM.CATALOG", "SYSTEM.FUNCTION", "SYSTEM.SEQUENCE", "SYSTEM.STATS", "User"]
5. 删除
删除列
hbase(main):008:0> delete 'User', 'row1', 'info:age'
0 row(s) in 0.0290 seconds
删除所有行
hbase(main):014:0> deleteall 'User', 'row2'
0 row(s) in 0.0090 seconds
删除表中所有数据
hbase(main):016:0> truncate 'User'
Truncating 'User' table (it may take a while):
- Disabling table...
- Truncating table...
0 row(s) in 3.6610 seconds
Hbase 单机关闭 ./hbase-daemon.sh stop master
单机启动 ./start-hbase.sh
2246

被折叠的 条评论
为什么被折叠?



