一、建表语句
hbase(main):003:0> create 't1', 'f1' , 'f2' , 'f3' --建表语句
0 row(s) in 9.5860 seconds
=> Hbase::Table - t1
hbase(main):004:0> desc 't1' --查看t1列族信息
Table t1 is ENABLED
t1
COLUMN FAMILIES DESCRIPTION
{NAME => 'f1', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE'
, MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 't
rue'}
{NAME => 'f2', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE'
, MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 't
rue'}
{NAME => 'f3', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE'
, MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 't
rue'}
3 row(s) in 0.1610 seconds
二、插入数据
hbase(main):006:0> put 't1' , '123' , 'f1:name' , 'zs' --给t1表中插入数据【‘123’--RowKey ‘f1:name’---f1列族的name属性 ‘zs’---列族的值】
0 row(s) in 0.2400 seconds
hbase(main):007:0> get 't1' , '123' , 'f1' --查看数据,查看t1表,RowKey为123的f1列族的数据
COLUMN CELL
f1:name timestamp=1509830487496, value=zs
1 row(s) in 0.1710 seconds
三、修改列族版本信息【默认为1,即只能存一个版本】
hbase(main):002:0> alter 't1' , {NAME => 'f1' , VERSION => 3} --将t1表f1列族版本上限修改为3
Unknown argument ignored for column family f1: 1.8.7
Updating all regions with the new schema...
0/1 regions updated.
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 5.9630 seconds
hbase(main):003:0> put 't1' , '123' , 'f1:sex' , 'woman' ---给f1列族sex属性在插入两个women
0 row(s) in 0.1810 seconds
hbase(main):004:0> get 't1' , '123' , {COLUMN => 'f1:sex' , VERSIONS => 3 } --查询t1表f1列族属性为sex的值,找最近的三个版本。得到如下列表
COLUMN CELL
f1:sex timestamp=1509831317010, value=woman
f1:sex timestamp=1509831094958, value=woman
f1:sex timestamp=1509830728187, value=man
3 row(s) in 0.0690 seconds
四、查看hbase数据在hadoop中的存储
我们使用浏览器访问Hadoop【http://192.168.0.201:50070】,进入如下菜单
进去后我们可以看到如下界面
访问/hbase/data/default目录可以看到如下信息
点击t1,看到如下界面
点击region,看到如下界面
注意:当你向列族插入数据后,可能在hadoop文件系统中看不到,这是因为当前插入的数据还在MemStore中,当当MenStore满了之后,数据将写入StoreFile/HFile即文件系统。我们也可以手动使其写入文件系统,命令如下:flush ‘t1’ --其中t1为刚刚建的表名。
五、删除表
hbase(main):005:0> disable 't1' ---将t1置为不可用状态
0 row(s) in 7.2670 seconds
hbase(main):006:0> drop 't1' ---删除t1
0 row(s) in 6.1120 seconds
hbase(main):007:0> list ---查看表信息,发现没有了t1
TABLE
0 row(s) in 0.2180 seconds
=> []