扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
操作环境:
专注于为中小企业提供成都网站建设、网站制作服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业山东免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了近千家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
操作系统: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
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流