Hbase Shell 数据操作说明

 

启动、关闭hbase

./bin/start-hbase.sh
./bin/stop-hbase.sh


查询HBase版本。它的语法如下:

[root@hadoop03 ~]# hbase shell
hbase(main):010:0> version


建表
create ‘<table name>’,’<column family>’
create 'emp', 'personal data', ’professional data’

清空表
truncate ‘lmj_test’

删除表
分两步,首先disable 'lmj_test',然后drop 'lmj_test'


列出所有表:list


表空间:
create_namespace 'name'
drop_namespace 'name'
列出所有表空间:list_namespace
查看表空间:describe_namespace 'name'

 

使用put命令,可以插入行到一个表。它的语法如下:
put ’<namespace:table name>’,’row1’,’<colfamily:colname>’,’<value>’
(表空间名非必填)

put 'emp','1','personal data:name','raju'
put 'emp','1','personal data:city','hyderabad'
put 'emp','1','professional data:designation','manager'
put 'emp','1','professional data:salary','50000'

put 'emp','2','personal data:name','mike'
put 'emp','2','personal data:city','NanJing'
put 'emp','2','professional data:designation','CEO'
put 'emp','2','professional data:salary','99000'


查询表中所有数据:
hbase(main):026:0> scan 'emp'
ROW COLUMN+CELL
1 column=personal data:city, timestamp=1510047547743, value=hyderabad
1 column=personal data:name, timestamp=1510047519200, value=raju
1 column=professional data:designation, timestamp=1510047567498, value=manager
1 column=professional data:salary, timestamp=1510047577830, value=50000
2 column=personal data:city, timestamp=1510047806635, value=NanJing
2 column=personal data:name, timestamp=1510047795408, value=mike
2 column=professional data:designation, timestamp=1510047812168, value=CEO
2 column=professional data:salary, timestamp=1510047818080, value=99000
2 row(s) in 0.0240 seconds


使用get命令获取一行数据。它的语法如下:
get ’<table name>’,’row1’
get 'emp' , '1'


使用get方法读取指定列:
hbase>get 'table name', ‘rowid’, {COLUMN => ‘column family:column name ’}
get 'emp', '2', {COLUMN=>'personal data:name'}


删除一行中所有单元格。下面给出是 deleteall 命令的语法。
deleteall ‘<table name>’, ‘<row>’

使用 delete 命令,可以在一个表中删除特定单元格。 delete 命令的语法如下:
delete ‘<table name>’, ‘<row>’, ‘<column name >’, ‘<time stamp>’

 

posted @ 2017-11-09 10:50  星瑞  阅读(8805)  评论(0编辑  收藏  举报