[server@hadoop102 bin]$ cd /opt/module/hbase/
[server@hadoop102 hbase]$ bin/start-hbase.sh
starting master, logging to /opt/module/hbase/bin/../logs/hbase-server-master-hadoop102.out
hadoop104: starting regionserver, logging to /opt/module/hbase/bin/../logs/hbase-server-regionserver-hadoop104.out
hadoop103: starting regionserver, logging to /opt/module/hbase/bin/../logs/hbase-server-regionserver-hadoop103.out
hadoop102: starting regionserver, logging to /opt/module/hbase/bin/../logs/hbase-server-regionserver-hadoop102.out
[server@hadoop102 hbase]$ bin/hbase shell
hbase(main):001:0> list
TABLE
0 row(s) in 1.0690 seconds
=> []
查看命名空间
hbase(main):002:0> list_namespace
NAMESPACE
default
hbase
2 row(s) in 0.0890 seconds
创建表
hbase(main):003:0> create 'customer','info'
0 row(s) in 3.1810 seconds
=> Hbase::Table - customer
describe 查看表结构,ENABLED 代表表可用
hbase(main):004:0> describe 'customer'
Table customer is ENABLED
customer
COLUMN FAMILIES DESCRIPTION
{NAME => 'info', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BL
OCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZ
E => '65536', REPLICATION_SCOPE => '0'}
1 row(s) in 0.4230 seconds
插入数据
put 'customer','1001','info:name','Sally'
put 'customer','1001','info:sex','female'
put 'customer','1001','info:age','18'
put 'customer','1002','info:name','John'
put 'customer','1002','info:age','20'
put 'customer','1002','info:sex','male'
put 'customer','1003','info:name','Mike'
put 'customer','1003','info:age','18'
put 'customer','1003','info:sex','male'
put 'customer','10010','info:name','Amy'
扫描查看表数据
hbase(main):019:0> scan 'customer'
ROW COLUMN+CELL
1001 column=info:age, timestamp=1633527313946, value=18
1001 column=info:name, timestamp=1633527302090, value=Sally
1001 column=info:sex, timestamp=1633527308613, value=female
10010 column=info:name, timestamp=1633527641373, value=Amy
1002 column=info:age, timestamp=1633527640666, value=20
1002 column=info:name, timestamp=1633527640541, value=John
1002 column=info:sex, timestamp=1633527640741, value=male
1003 column=info:age, timestamp=1633527640993, value=18
1003 column=info:name, timestamp=1633527640835, value=Mike
1003 column=info:sex, timestamp=1633527641237, value=male
4 row(s) in 0.1220 seconds
STOPROW 不包含结束
hbase(main):023:0> scan 'customer',{STARTROW => '1001' ,STOPROW => '1001' }
ROW COLUMN+CELL
1001 column=info:age, timestamp=1633527313946, value=18
1001 column=info:name, timestamp=1633527302090, value=Sally
1001 column=info:sex, timestamp=1633527308613, value=female
1 row(s) in 0.0790 seconds
hbase(main):024:0> scan 'customer',{STARTROW => '1001' ,STOPROW => '1003' }
scan 'customer',{STARTROW => '1001' ,STOPROW => '1004' }ROW COLUMN+CELL
1001 column=info:age, timestamp=1633527313946, value=18
1001 column=info:name, timestamp=1633527302090, value=Sally
1001 column=info:sex, timestamp=1633527308613, value=female
10010 column=info:name, timestamp=1633527641373, value=Amy
1002 column=info:age, timestamp=1633527640666, value=20
1002 column=info:name, timestamp=1633527640541, value=John
1002 column=info:sex, timestamp=1633527640741, value=male
3 row(s) in 0.0960 seconds
hbase(main):025:0> scan 'customer',{STARTROW => '1001' ,STOPROW => '1004' }
ROW COLUMN+CELL
1001 column=info:age, timestamp=1633527313946, value=18
1001 column=info:name, timestamp=1633527302090, value=Sally
1001 column=info:sex, timestamp=1633527308613, value=female
10010 column=info:name, timestamp=1633527641373, value=Amy
1002 column=info:age, timestamp=1633527640666, value=20
1002 column=info:name, timestamp=1633527640541, value=John
1002 column=info:sex, timestamp=1633527640741, value=male
1003 column=info:age, timestamp=1633527640993, value=18
1003 column=info:name, timestamp=1633527640835, value=Mike
1003 column=info:sex, timestamp=1633527641237, value=male
4 row(s) in 0.0650 seconds
更新指定字段的数据
put 'customer','1001','info:name','Kate'
hbase(main):026:0> scan 'customer',{STARTROW => '1001' ,STOPROW => '1001' }
ROW COLUMN+CELL
1001 column=info:age, timestamp=1633527313946, value=18
1001 column=info:name, timestamp=1633527302090, value=Sally
1001 column=info:sex, timestamp=1633527308613, value=female
1 row(s) in 0.1180 seconds
hbase(main):027:0> put 'customer','1001','info:name','Kate'
0 row(s) in 0.0470 seconds
hbase(main):028:0> scan 'customer',{STARTROW => '1001' ,STOPROW => '1001' }
ROW COLUMN+CELL
1001 column=info:age, timestamp=1633527313946, value=18
1001 column=info:name, timestamp=1633528201324, value=Kate
1001 column=info:sex, timestamp=1633527308613, value=female
1 row(s) in 0.0290 seconds
查看指定行的数据,timestamp是时间戳
hbase(main):029:0> get 'customer','1002'
COLUMN CELL
info:age timestamp=1633527640666, value=20
info:name timestamp=1633527640541, value=John
info:sex timestamp=1633527640741, value=male
1 row(s) in 0.1420 seconds
查看指定列族:列的数据
hbase(main):030:0> get 'customer','1002','info:name'
COLUMN CELL
info:name timestamp=1633527640541, value=John
1 row(s) in 0.0880 seconds
统计表数据行数
hbase(main):031:0> count 'customer'
4 row(s) in 0.0780 seconds
=> 4
删除某rowkey全部数据
hbase(main):032:0> deleteall 'customer','10010'
0 row(s) in 0.1140 seconds
hbase(main):033:0> scan 'customer'
ROW COLUMN+CELL
1001 column=info:age, timestamp=1633527313946, value=18
1001 column=info:name, timestamp=1633528201324, value=Kate
1001 column=info:sex, timestamp=1633527308613, value=female
1002 column=info:age, timestamp=1633527640666, value=20
1002 column=info:name, timestamp=1633527640541, value=John
1002 column=info:sex, timestamp=1633527640741, value=male
1003 column=info:age, timestamp=1633527640993, value=18
1003 column=info:name, timestamp=1633527640835, value=Mike
1003 column=info:sex, timestamp=1633527641237, value=male
3 row(s) in 0.1500 seconds
删除某rowkey的某一列数据
hbase(main):034:0> delete 'customer','1002','info:sex'
0 row(s) in 0.0600 seconds
hbase(main):035:0> scan 'customer'
ROW COLUMN+CELL
1001 column=info:age, timestamp=1633527313946, value=18
1001 column=info:name, timestamp=1633528201324, value=Kate
1001 column=info:sex, timestamp=1633527308613, value=female
1002 column=info:age, timestamp=1633527640666, value=20
1002 column=info:name, timestamp=1633527640541, value=John
1003 column=info:age, timestamp=1633527640993, value=18
1003 column=info:name, timestamp=1633527640835, value=Mike
1003 column=info:sex, timestamp=1633527641237, value=male
3 row(s) in 0.0330 seconds
清空表数据
hbase(main):036:0> truncate 'customer'
Truncating 'customer' table (it may take a while):
- Disabling table...
- Truncating table...
0 row(s) in 4.7380 seconds
删除表
hbase(main):037:0> disable 'customer'
0 row(s) in 2.3120 seconds
hbase(main):038:0> drop 'customer'
0 row(s) in 1.3580 seconds
hbase(main):039:0> list
TABLE
0 row(s) in 0.0300 seconds
=> []
创建命名空间
hbase(main):041:0> create_namespace 'shop'
0 row(s) in 0.9450 seconds
hbase(main):042:0> list
TABLE
0 row(s) in 0.0270 seconds
=> []
在命名空间下创建表
hbase(main):043:0> create 'shop:customer','info'
0 row(s) in 2.3160 seconds
=> Hbase::Table - shop:customer
http://hadoop102:16010/master-status#userTables
插入数据
hbase(main):057:0> put 'shop:customer','1001','info:name','Sally'
0 row(s) in 0.0470 seconds
hbase(main):058:0> put 'shop:customer','1001','info:sex','female'
0 row(s) in 0.0530 seconds
hbase(main):059:0> put 'shop:customer','1001','info:age','18'
put 'shop:customer','1002','info:name','John'
put 'shop:customer','1002','info:age','20'
put 'shop:customer','1002','info:sex','male'
0 row(s) in 0.0270 seconds
put 'shop:customer','1003','info:name','Mike'
put 'shop:customer','1003','info:age','18'
hbase(main):060:0> put 'shop:customer','1002','info:name','John'
0 row(s) in 0.0490 seconds
hbase(main):061:0> put 'shop:customer','1002','info:age','20'
0 row(s) in 0.0120 seconds
hbase(main):062:0> put 'shop:customer','1002','info:sex','male'
0 row(s) in 0.0270 seconds
hbase(main):063:0> put 'shop:customer','1003','info:name','Mike'
0 row(s) in 0.0130 seconds
hbase(main):064:0> put 'shop:customer','1003','info:age','18'
0 row(s) in 0.0190 seconds
hbase(main):065:0> put 'shop:customer','1003','info:sex','male'
0 row(s) in 0.0230 seconds
hbase(main):066:0> put 'shop:customer','10010','info:name','Amy'
0 row(s) in 0.0430 seconds
hbase(main):068:0> scan 'shop:customer'
ROW COLUMN+CELL
1001 column=info:age, timestamp=1633529536069, value=18
1001 column=info:name, timestamp=1633529517118, value=Sally
1001 column=info:sex, timestamp=1633529535913, value=female
10010 column=info:name, timestamp=1633529537806, value=Amy
1002 column=info:age, timestamp=1633529536211, value=20
1002 column=info:name, timestamp=1633529536169, value=John
1002 column=info:sex, timestamp=1633529536266, value=male
1003 column=info:age, timestamp=1633529536412, value=18
1003 column=info:name, timestamp=1633529536312, value=Mike
1003 column=info:sex, timestamp=1633529536477, value=male
4 row(s) in 0.1160 seconds






网友评论