1. Basic operation commands
command | meaning | Instance |
---|---|---|
status | Display state | status ‘hadoop1’ |
whoami | Display current users of HBase | whoami |
list | Show all current tables | list |
count | Count the number of records in the specified table | count ‘user’ |
describe | Display table structure information | describe ‘user’ |
exists | Check if the table exists | exists ‘user’ |
is_enabled/is_disabled | Check if the table is enabled/disabled | is_enabled ‘user’ |
alter | Change the mode of a table or column family | alter ‘user’, NAME => ‘CF2’, VERSIONS => 2 |
disable/enable | Enable/disable a table | disable ‘user’ |
drop | Delete table | drop ‘user’ |
truncate | Disable table | trancate ‘user’ |
-
Open the HBase shell
cd /export/servers/hbase-2.0.0 bin/hbase shell
-
Create table, add data
# 创建表 create 'user', 'info', 'data' # 向user表中插入信息,row key为rk0001,列族info中添加name列标示符,值为zhangsan put 'user', 'rk0001', 'info:name', 'zhangsan' # 向user表中插入信息,row key为rk0001,列族info中添加gender列标示符,值为female put 'user', 'rk0001', 'info:gender', 'female' # 向user表中插入信息,row key为rk0001,列族info中添加age列标示符,值为20 put 'user', 'rk0001', 'info:age', 20 # 向user表中插入信息,row key为rk0001,列族data中添加pic列标示符,值为picture put 'user', 'rk0001', 'data:pic', 'picture'
-
How many rows of data are counted
count 'user'
2. Query operation
-
Query by get (get rowkey)
# 获取user表中row key为rk0001的所有信息 get 'user', 'rk0001'
# 获取user表中row key为rk0001,info列族的信息 get 'user', 'rk0001', 'info'
# 获取user表中row key为rk0001,info列族的name、age列标示符的信息 get 'user', 'rk0001', 'info:name', 'info:age'
# 获取user表中row key为rk0001,info、data列族的信息, 两种写法 get 'user', 'rk0001', 'info', 'data' get 'user', 'rk0001', { COLUMN => ['info', 'data']}
#获取user表中row key为rk0001,cell的值为zhangsan的信息 get 'user', 'rk0001', { FILTER => "ValueFilter(=, 'binary:zhangsan')"}
# 获取user表中row key为rk0001,列标示符中含有a的信息 get 'user', 'rk0001', { FILTER => "(QualifierFilter(=,'substring:a'))"}
-
Query by scan (scan condition)
get can not get all the information in the table, to get all the information in the table, you need to pass scan
# 查询user表中的所有信息 scan 'user'
# 查询user表中列族为info的信息 scan 'user', { COLUMNS => 'info'}
# 查询user表中列族为info和data的信息 scan 'user', { COLUMNS => ['info', 'data']} # 查询user表中列族为info列为name和列族为data列为pic的信息 scan 'user', { COLUMNS => ['info:name', 'data:pic']}
# 查询user表中列族为info、列标示符为name的信息,并且版本最新的5个 scan 'user', { COLUMNS => ['info', 'data'], FILTER => "(QualifierFilter(=,'substring:a'))"} # 查询user表中列族为info,rk范围是[rk0001, rk0003)的数据 scan 'user', { COLUMNS => 'info', STARTROW => 'rk0001', ENDROW => 'rk0003'} # 查询user表中row key以rk字符开头的 scan 'user',{ FILTER=>"PrefixFilter('rk')"}
# 查询user表中指定范围的数据 scan 'user', { TIMERANGE => [1582873430274, 1582873430774]}
3. Update operation
-
Update data: The operation is the same as inserting
-
updated version
# 将user表的f1列族版本号改为5 alter 'user', NAME => 'info', VERSIONS => 5
4. Delete operation
-
Specify rowkey and column name to delete
# 删除user表row key为rk0001,列标示符为info:name的数据 delete 'user', 'rk0001', 'info:name' scan 'user'
-
Specify rowkey, column name and field value to delete
# 删除user表row key为rk0001,列标示符为data:pic,timestamp为1392383705316的数据 delete 'user', 'rk0001', 'data:pic', 1582873430274
-
Delete a column family
alter 'user', NAME => 'info', METHOD => 'delete' 或 alter 'user', 'delete' => 'info'
-
Clear table data
truncate 'user' scan 'user'
-
Delete table
# 首先需要先让该表为disable状态 disable 'user' # 删除表 drop 'user' list