查看有哪些表
hbase(main):030:0> list
TABLE
mytable
t_users
test
3 row(s) in 0.0160 seconds
=> ["mytable", "t_users", "test"]
创建表
# 语法:create <table>, {NAME => <family>, VERSIONS => <VERSIONS>}
#或者 create <table>,<列>
hbase(main):024:0> create 't_users','info'
0 row(s) in 1.2600 seconds
=> Hbase::Table - t_users
查看表结构
hbase(main):028:0> describe 't_users'
Table t_users is ENABLED
t_users
COLUMN FAMILIES DESCRIPTION
{NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CEL
LS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
1 row(s) in 0.0440 seconds
修改表结构
#修改表结构必须先disable
# 语法:alter 't1', {NAME => 'f1'}, {NAME => 'f2', METHOD => 'delete'}
# 例如:修改表test1的cf的TTL为180天
hbase(main)> disable 'test1'
hbase(main)> alter 'test1',{NAME=>'body',TTL=>'15552000'},{NAME=>'meta', TTL=>'15552000'}
hbase(main)> enable 'test1'
删除表
#分两步:首先disable,然后drop
hbase(main)> disable 'tableName'
hbase(main)> drop 'tableName'
添加数据
#put
# 语法:put <table>,<rowkey>,<family:column>,<value>
hbase(main):010:0> put 'mytable','first','cf:message','hello'
0 row(s) in 0.0610 seconds
查询数据
# 语法:get <table>,<rowkey>,[<family:column>,....]
hbase(main):021:0> get 'mytable','last'
COLUMN CELL
cf:_version timestamp=1492179089588, value=1.1
cf:message timestamp=1492178911594, value=xuyw
2 row(s) in 0.0330 seconds
扫描表
# 语法:scan <table>, {COLUMNS => [ <family:column>,.... ], LIMIT => num}
# 例如:扫描表test的前4条数据
hbase(main)> scan 'test',{LIMIT=>4}
查询表中的数据行数
# 语法:count <table>, {INTERVAL => intervalNum, CACHE => cacheNum}
删除行中的某个列值(删除整行,无需列名)
# 语法:delete <table>, <rowkey>, <family:column> , 必须指定列名
hbase(main)> delete 'test','last','cf:msg'
删除表中的所有数据
# 语法: truncate <table>