1.进入Hbase shell命令
$>hbase shell
2.建议参照“help”命令
$>help
3.shell命令
create创建表指令:
hbase(main):021:0> create 'customer','baseinfo','address'
put插入数据:
语法: put 't' ,'r', 'c', 'v' (表 ,行,列名,值)
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','长春'
scan扫描表:scan 't'
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
说明:当前显示的为一条记录;
get获取指令:
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
delete删除记录指令:
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}
通过scan '表名',{VERSIONS=>*}指令,检索当前表的数据版本;
执行delete删除命令时,如需按照ts(timestamp)时间戳进行删除操作时,之前版本一并删除掉;
drop删除table指令:
hbase(main):084:0> disable 'tablename' //说明:禁用table
hbase(main):084:0> drop ' 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" //强制负载均衡
4.测试,使用Ruby语法添加数据
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
【循环插入数据】
5.merge合并
---------------------------------------
1.merge_region合并命令
hbase(main):010:0> merge_region '857d52f5591906576a85809db8522cbf','441d5e059755eae0f0b4582e915f6408'
2.move移动region指令:
hbase(main):012:0> move '28157277880b3d345f1a8a65c84cab73' //随机指定regionserver
hbase(main):012:0> move '28157277880b3d345f1a8a65c84cab73','slave1,16020,1533138423796' //指定regionserver
3.预分区:事先指定分区(rowkey设计至关重要)
命令如下:
hbase> create 'ns1:t1', 'f1', SPLITS => ['10', '20', '30', '40']
说明:在ns1命名空间下,创建t1表,列簇为f1;预分区为5个:['',10);[10,20);[20,30);[30,40);[40,'']