$>hbase shell
hbase(main):021:0> create 'customer','baseinfo','address'
hbase(main):021:0> put 'customer','row-1','baseinfo:name','zhangsan'
hbase(main):021:0> put 'customer','row-1','baseinfo:age',12
hbase(main):021:0> put 'customer','row-1','baseinfo:sex','男'
hbase(main):021:0> put 'customer','row-1','address:city','长春'
hbase(main):021:0> scan 'customer'
ROW COLUMN+CELL
row-1 column=address:city, timestamp=1533057164343, value=changchun
row-1 column=baseinfo:age, timestamp=1533057275350, value=23
row-1 column=baseinfo:name, timestamp=1533056802314, value=zhangsan
row-1 column=baseinfo:sex, timestamp=1533057120030, value=\xE7\x94\xB7\x0A
1 row(s) in 0.1030 seconds
说明:当前显示的为一条记录;
hbase(main):021:0> get 'customer','row-1'
COLUMN CELL
address:city timestamp=1533057164343, value=changchun
baseinfo:age timestamp=1533057275350, value=23
baseinfo:name timestamp=1533056802314, value=zhangsan
baseinfo:sex timestamp=1533057120030, value=\xE7\x94\xB7\x0A
1 row(s) in 0.1500 seconds
hbase(main):072:0> delete 'customer','row-2','baseinfo:name'
describe描述指令检索结构:
hbase(main):084:0> desc 'customer'
Table customer is ENABLED
customer
COLUMN FAMILIES DESCRIPTION
{NAME => 'address', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
{NAME => 'baseinfo', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
2 row(s) in 0.5850 seconds
VERSION版本,默认version为1,按timestamp时间戳进行降序:
修改版本号:hbase(main):086:0> alter 'customer',{NAME=>'baseinfo',VERSIONS=>5}
hbase(main):084:0> desc 'customer'
通过scan '表名',{VERSIONS=>*}指令,检索当前表的数据版本;
执行delete删除命令时,如需按照ts(timestamp)时间戳进行删除操作时,之前版本一并删除掉;
drop删除table指令:
hbase(main):084:0> disable 'ns1:tablename' //说明:禁用table
hbase(main):084:0> drop 'ns1:tablename' //说明:删除table
get_table指令:将table映射成相对应的变量值(table实例),通过table实例对表进行相关操作
hbase(main):117:0> t1 = get_table 'customer'
hbase(main):118:0> t1.scan
hbase(main):119:0> t1.put 'row-2','baseinfo:name','zhangsan'
hbase(main):120:0> t1.get 'row-2'
namespace名字空间,相当于传统数据库的表空间:
hbase(main):003:0> create_namespace 'ns1',{'author'=>'zhangyuejiu','data'=>'2018-07-31'}
hbase(main):005:0> describe_namespace 'ns1'
DESCRIPTION
{NAME => 'ns1', author => 'zhangyuejiu', data => '2018-07-31'}
1 row(s) in 0.0620 seconds
balance负载均衡指令,需使用开关模式,原因负载均衡比较耗费资源:
hbase(main):005:0> balance_switch true //开启负载均衡
hbase(main):005:0> balancer //执行负载均衡
hbase(main):005:0> balance_switch false //关闭负载均衡
hbase(main):005:0> balancer "force" //强制负载均衡
hbase(main):003:0> create_namespace 'ns1'
hbase(main):003:0> create 'ns1:student','info'
hbase(main):003:0> for i in 'a'..'z' do for j in 'a'..'z' do \
hbase(main):009:2* put 'ns1:student',"row-#{i}#{j}","info:#{j}","#{j}" end end