名称 | 命令表达式 |
---|---|
创建表 | create ‘表名称’, ‘列名称1’,‘列名称2’,‘列名称N’ |
添加记录 | put ‘表名称’, ‘行名称’, ‘列名称:’, ‘值’ |
查看记录 | get ‘表名称’, ‘行名称’ |
查看表中的记录总数 | count ‘表名称’ |
删除记录 | delete ‘表名’ ,‘行名称’ , ‘列名称’ |
删除一张表 | 先要屏蔽该表,才能对该表进行删除,第一步 disable ‘表名称’ 第二步 drop ‘表名称’ |
查看所有记录 | scan “表名称” |
查看某个表某个列中所有数据 | scan “表名称” , [‘列名称:’] |
更新记录 | 就是重写一遍进行覆盖 |
1.一般操作
1.1.查询服务器状态
hbase(main):008:0> status
1 active master, 0 backup masters, 1 servers, 0 dead, 2.0000 average load
1.2 查询hive版本
hbase(main):009:0> version
1.2.6, rUnknown, Mon May 29 02:25:32 CDT 2017
2.DDL操作
DDL(data definition language)数据库定义语言:其实就是我们在创建表的时候用到的一些sql,比如说:CREATE、ALTER、DROP等。DDL主要是用在定义或改变表的结构,数据类型,表之间的链接和约束等初始化工作上。
2.1 创建一个表
hbase>create ‘table_name’, {NAME=>‘columnFamily’}, {NAME=>‘columnFamily2’}…
=====>(更简化版本):create ‘table_name’,‘columnFamily’
创建表hbase_test有两个列族CF1和CF2
hbase(main):041:0>create 'hbase_test', {NAME=>'cf1'},{NAME=>'cf2'}
hbase(main):014:0> create 'hbase_test',{NAME=>'cf1'},{NAME=>'cf2'}
0 row(s) in 2.2310 seconds
=> Hbase::Table - hbase_test
hbase(main):015:0> create 'hbase_test2','cf1','cf2'
0 row(s) in 2.2340 seconds
=> Hbase::Table - hbase_test2
hbase(main):016:0> list
TABLE
hbase_test
hbase_test2
member
3 row(s) in 0.0130 seconds
=> ["hbase_test", "hbase_test2", "member"]
hbase(main):017:0>
hbase(main):016:0> list
TABLE
hbase_test
hbase_test2
member
3 row(s) in 0.0130 seconds
hbase(main):017:0> describe 'hbase_test'
Table hbase_test is ENABLED
hbase_test
COLUMN FAMILIES DESCRIPTION
{NAME => 'cf1', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION
_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL
=> 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY =>
'false', BLOCKCACHE => 'true'}
{NAME => 'cf2', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION
_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL
=> 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY =>
'false', BLOCKCACHE => 'true'}
2 row(s) in 0.0630 seconds
hbase(main):018:0>
2.4 删除一个列族,alter,disable,enable
我们之前建了3个列族,但是发现member_id这个列族是多余的,因为他就是主键,所以我们要将其删除。
hbase(main):011:0> alter 'member',{NAME=>'member_id',METHOD=>'delete'}
Updating all regions with the new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 3.1700 seconds
查看表描述
hbase(main):012:0> describe 'member'
Table member is ENABLED
member
COLUMN FAMILIES DESCRIPTION
{NAME => 'address', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICA
TION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0',
TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY
=> 'false', BLOCKCACHE => 'true'}
{NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATIO
N_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL
=> 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY =>
'false', BLOCKCACHE => 'true'}
2 row(s) in 0.0360 seconds
该列族已经删除
2.5 命令禁用表
disable 'table_name'
2.6 命令启用表
enable 'table_name'
2.7 清空&删除
清空:truncate 'table_name'
删除:先disable 在drop (1)disable ‘table_name’(2) drop ‘table_name’
2.8 查询表是否存在
命令:exists ‘table_name’
命令:is_enabled ' table_name '
命令:is_disabled ‘table_name’
2.11 修改表
需要先disable ‘table_name’,修改完成后enable ‘table_name’
示例:
alter 'table_name',{NAME=>'cf1'},{NAME=>'cf2'}
3.DML操作
DML(data manipulation language)数据操纵语言:就是我们最经常用到的 SELECT、UPDATE、INSERT、DELETE。 主要用来对数据库的数据进行一些操作。
3.1 插入数据
命令:put ‘table_name’,’ rowKey’,’列簇:列’,’value’
3.2 获取一条数据
3.2.1 获取一个id的所有数据
命令: get ‘table_name’ , ‘rowKey’
命令: get ‘table_name’ , ‘rowKey’, ‘列簇’
命令: get ‘table_name’ , ‘rowKey’, ‘列簇:列’
命令:put ‘table_name’,’ rowKey’,’列簇:列’,’value’
3.4.通过timestamp来获取数据
命令:get ‘table_name’,’rowKey’,{COLUMN=>’info:age’,TIMESTAMP=>’ 1547693223057’}
命令: scan ‘table_name’
命令: delete ‘table_name’,'rowKey','列簇:列'
3.7删除整行
命令:deteleall ‘table_name’,’rowKey’
命令:count ‘table_name’