1. Create 创建表
hbase(main):015:0> create 'student','info'
0 row(s) in 3.8800 seconds
创建student table, 其中一个列族为info
2. list 列出所有table
hbase(main):017:0> list
TABLE
student
test
2 row(s) in 0.0430 seconds
3. describe 描述表格的属性
hbase(main):016:0> describe 'student'
DESCRIPTION ENABLED
'student', {NAME => 'info', DATA_BLOCK_ENCODING => true
'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCOPE =>
'0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_V
ERSIONS => '0', TTL => '2147483647', KEEP_DELETED_C
ELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY =>
'false', ENCODE_ON_DISK => 'true', BLOCKCACHE => '
true'}
1 row(s) in 0.0840 seconds
4. alter 改变表格的属性
在使用alter之前,必须先disable 表格,否则会抛出org.apache.hadoop.hbase.TableNotDisabledException异常。
4.1 增加一个列族
1) 首先disable 表格
hbase(main):027:0> disable 'student'
0 row(s) in 2.0880 seconds
2) 使用alter增加一个列族
hbase(main):028:0> alter 'student', {NAME => 'course'}
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 1.1690 seconds
3) 通过describe 命令查看可以发现student表中多了一个列族
hbase(main):029:0> describe 'student'
DESCRIPTION ENABLED
'student', {NAME => 'course', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', COMPRESSION => 'NONE', VERSIONS => '3', T false
TL => '2147483647', MIN_VERSIONS => '0', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536', ENCODE_ON_DISK => 'true', IN_MEMORY => 'false', BLOCKCACH
E => 'true'}, {NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', VERSIONS => '3', COMPRESSION => 'NONE',
MIN_VERSIONS => '0', TTL => '2147483647', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false', ENCODE_ON_DISK => 'true', BLOCKCAC
HE => 'true'}
1 row(s) in 0.0400 seconds
4.2 删除列族
hbase(main):003:0> alter 'student', {NAME => 'course', METHOD => 'delete'}
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 1.3040 seconds
hbase(main):004:0> describe 'student'
DESCRIPTION ENABLED
'student', {NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN false
_VERSIONS => '0', TTL => '2147483647', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false', ENCODE_ON_DISK => 'true', BLOCKCACHE
=> 'true'}
1 row(s) in 0.0680 seconds
5. put 插入数据, 格式为: put '表名', '行名', '列族名', 'value' , timestamp
hbase(main):007:0> put 'student','max','info:age','20'
0 row(s) in 0.1050 seconds
hbase(main):008:0> put 'student','max','info:gender','male'
0 row(s) in 0.0360 seconds
6. scan 列出表格中所有数据
hbase(main):009:0> scan 'student'
ROW COLUMN+CELL
max column=info:age, timestamp=1396872116527, value=20
max column=info:gender, timestamp=1396872131487, value=male
1 row(s) in 0.0590 seconds
7. get 查询单条数据, 格式为:get '表名‘,’行名‘ [,'列族名' , timestamp ]
hbase(main):011:0> get 'student', 'max'
COLUMN CELL
info:age timestamp=1396872116527, value=20
info:gender timestamp=1396872131487, value=male
2 row(s) in 0.0400 seconds
hbase(main):012:0> get 'student', 'max', 'info:age'
COLUMN CELL
info:age timestamp=1396872116527, value=20
1 row(s) in 0.0160 seconds
8. delete 删除数据, 格式为:delete '表名', '行名’, '列族名', timestamp
hbase(main):014:0> delete 'student', 'max', 'info:age'
0 row(s) in 0.0220 seconds
hbase(main):015:0> scan 'student'
ROW COLUMN+CELL
max column=info:gender, timestamp=1396872131487, value=male
1 row(s) in 0.8260 seconds
9. deleteall 删除整行数据
hbase(main):016:0> deleteall 'student','max'
0 row(s) in 0.0210 seconds
hbase(main):017:0> scan 'student'
ROW COLUMN+CELL
0 row(s) in 0.0170 seconds
10. truncate 清空整张表
hbase(main):018:0> truncate 'student'
Truncating 'student' table (it may take a while):
- Disabling table...
- Dropping table...
- Creating table...
0 row(s) in 10.3050 seconds