启动hadoop:start-all.sh
启动hbase:start-hbase.sh
启动hbase shell客户端,进入创表:
1.在HBase中创建‘sutdent’表,如图所示:
<1>创建命名空间,建立一个test的命名空间,通过如下describe命令来查看所建立的命名空间的详细信息,具体的命令如下:
#1、创建命名空间
hbase(main):006:0> create_namespace 'test'
Took 0.8661 seconds
#2、查看所建立的命名空间的详细信息
hbase(main):009:0> describe_namespace 'test'
DESCRIPTION
{NAME => 'test'}
Quota is disabled
Took 1.1768 seconds
<2>建立一个student表,有5个列族,有name,age,sex,id,score。具体的命令如下:
#1、查看当前数据库中有哪些表
hbase(main):010:0> list
TABLE
0 row(s)
Took 0.0386 seconds
=> []
#2、创建表student5
hbase(main):023:0> create 'student5','info1','info2'
Created table student5
Took 2.5662 seconds
=> Hbase::Table - student5
#3、其数据内容如下:
hbase(main):025:0> put 'student5','rk01','info1:name','zhangsan'
Took 0.5119 seconds
hbase(main):026:0> put 'student5','rk01','info1:age','18'
Took 0.0185 seconds
hbase(main):027:0> put 'student5','rk01','info1:sex','man'
Took 0.0166 seconds
hbase(main):030:0> put 'student5','rk01','info2:id','11111'
Took 0.0918 seconds
hbase(main):031:0> put 'student5','rk01','info2:score','90'
Took 0.0137 seconds
#4、查看表信息:
hbase(main):033:0> scan 'student5'
ROW COLUMN+CELL
rk01 column=info1:age, timestamp=1681358763438, value=18
rk01 column=info1:name, timestamp=1681358735922, value=zhangsan
rk01 column=info1:sex, timestamp=1681358779985, value=man
rk01 column=info2:id, timestamp=1681359019121, value=11111
rk01 column=info2:score, timestamp=1681359031401, value=90
1 row(s)
Took 0.3260 seconds
2.向表中插入至少两条数据(zhangsan,18,man,11111,90)
#插入第一条数据
hbase(main):025:0> put 'student5','rk01','info1:name','zhangsan'
Took 0.5119 seconds
hbase(main):026:0> put 'student5','rk01','info1:age','18'
Took 0.0185 seconds
hbase(main):027:0> put 'student5','rk01','info1:sex','man'
Took 0.0166 seconds
hbase(main):030:0> put 'student5','rk01','info2:id','11111'
Took 0.0918 seconds
hbase(main):031:0> put 'student5','rk01','info2:score','90'
Took 0.0137 seconds
#插入第二条数据
hbase(main):020:0> put 'student5','rk02','info1:name','zhhuan'
Took 0.4455 seconds
hbase(main):021:0> put 'student5','rk02','info1:age','22'
Took 0.0158 seconds
hbase(main):022:0> put 'student5','rk02','info1:sex','woman'
Took 0.0163 seconds
hbase(main):023:0> put 'student5','rk02','info2:id','11112'
Took 0.0212 seconds
hbase(main):024:0> put 'student5','rk02','info2:score','90'
Took 0.0378 seconds
#插入第三条数据:
hbase(main):028:0> put 'student5','rk03','info1:name','zhjie'
Took 0.1387 seconds
hbase(main):029:0> put 'student5','rk03','info1:age','30'
Took 0.0198 seconds
hbase(main):031:0> put 'student5','rk03','info2:id','11113'
Took 0.0223 seconds
hbase(main):032:0> put 'student5','rk03','info1:sex','man'
Took 0.0303 seconds
hbase(main):034:0> put 'student5','rk03','info2:score','93'
Took 0.0146 seconds
3.修改名字为zhangsan的性别为woman
#修改
hbase(main):046:0> put 'student5','rk01','info1:sex','woman'
Took 0.0497 seconds
#查询修改结果
4.查询性别为女的所有的人名
命令:
scan'student5',{FILTER=>"SingleColumnValueFilter('info1':'sex',=,'binary:woman') AND QualifierFilter(=,'binary:name') ",FORMATTER => 'toString'}
结果:
hbase(main):003:0> scan 'student5',{FILTER=>"SingleColumnValueFilter('info1':'sex',=,'binary:woman') AND QualifierFilter(=,'binary:name') ",FORMATTER => 'toString'}
ROW COLUMN+CELL
rk01 column=info1:name, timestamp=1682042269553, value=zhangsan
rk02 column=info1:name, timestamp=1682041446301, value=zhhuan
2 row(s)
Took 0.6609 seconds
5.删除名字为张三的数据
#删除数据
hbase(main):017:0> deleteall 'student5','zhangsan'
Took 0.1570 seconds