操作环境:
操作系统:Ubuntu 16.04.6 LTS
HBase版本:HBase 1.1.5
HBase是一个高可靠、高性能、面向列、可伸缩的分布式数据库,主要用来存储非结构化和半结构化的松散数据。
hadoop@dblab:/usr/local/hadoop$ cd /usr/local/hbase
hadoop@dblab:/usr/local/hbase$ bin/start-hbase.sh #启动HBase
hadoop@dblab:/usr/local/hbase$ bin/hbase shell #进入Shell模式
#创建student表
hbase(main):001:0> create 'student','Sname','Ssex','Sage','Sdept','course'
0 row(s) in 1.6440 seconds
=> Hbase::Table - student
#查看数据库中已经创建的表
hbase(main):002:0> list
TABLE
student
1 row(s) in 0.0410 seconds
=> ["student"]
#查看表结构
hbase(main):003:0> describe 'student'
Table student is ENABLED
student
COLUMN FAMILIES DESCRIPTION
{NAME => 'Sage', 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 => 'Sdept', 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 => 'Sname', 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 => 'Ssex', 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 => 'course', 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'}
5 row(s) in 0.1650 seconds
#向表中添加数据
hbase(main):004:0> put 'student','95001','Sname','LiYing'
hbase(main):004:0> put 'student','95001','Sname','LiYing'
hbase(main):005:0> put 'student','95001','Ssex','male'
hbase(main):006:0> put 'student','95001','Sage','22'
hbase(main):007:0> put 'student','95001','Sdept','Cs'
hbase(main):008:0> put 'student','95001','Course:math','80'
ERROR: Unknown column family! Valid column names: Sage:*, Sdept:*, Sname:*, Ssex:*, course:*
hbase(main):009:0> put 'student','95001','course:math','80'
0 row(s) in 0.0330 seconds
#查看某个单元格数据
hbase(main):010:0> get 'student','95001'
COLUMN CELL
Sage: timestamp=1558580423554, value=22
Sdept: timestamp=1558580447276, value=Cs
Sname: timestamp=1558580336295, value=LiYing
Ssex: timestamp=1558580402507, value=male
course:math timestamp=1558580543129, value=80
5 row(s) in 0.0850 seconds
#查询表中有数据所
hbase(main):011:0> scan 'student'
ROW COLUMN+CELL
95001 column=Sage:, timestamp=1558580423554, value=22
95001 column=Sdept:, timestamp=1558580447276, value=Cs
95001 column=Sname:, timestamp=1558580336295, value=LiYing
95001 column=Ssex:, timestamp=1558580402507, value=male
95001 column=course:math, timestamp=1558580543129, value=80
1 row(s) in 0.0740 seconds
#删除95001行中的Ssex列的所有数据
hbase(main):014:0> delete 'student','95001','Ssex'
hbase(main):015:0> scan 'student'
ROW COLUMN+CELL
95001 column=Sage:, timestamp=1558580423554, value=22
95001 column=Sdept:, timestamp=1558580447276, value=Cs
95001 column=Sname:, timestamp=1558580336295, value=LiYing
95001 column=course:math, timestamp=1558580543129, value=80
#删除表中为95001行的全部数据
hbase(main):016:0> deleteall 'student','95001'
0 row(s) in 0.0390 seconds
#该表中所存在任何数据
hbase(main):017:0> scan 'student'
ROW COLUMN+CELL
#删除表
hbase(main):006:0> disable 'student'
hbase(main):009:0> drop 'student'
#退出数据库操作
hbase(main):018:0> exit
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。