HBASE SHELL学习
HBASE SHELL学习小白的Hbase学习笔记
目次
HBASE SHELL学习
1.启动hbase
2.进入hbase
3.help (查看HBASE SHELL支持的下令)
4.general (普遍的)
5.ddl - 表操作
1)create 创建表
2)describe 查看表的具体信息
3)alter 修改表
4)drop 删除表
5)关闭及启用表
6.namespace (定名空间)
1)create_namespace 创建定名空间
编辑
2)list_namespace 查看当前定名空间
3)describe_namespace 查看定名空间的具体信息
4)alter_namespace 修改定名空间
编辑
5)drop_namespace 删除空的定名空间
编辑
6)list_namespace_tables 查看指定定名空间下的表
7.dml
1)put 上传及修改数据操作
2)get 获取一行数据操作
3)scan 获取表中所有数据
4)list 查看所有表
5)count 统计表中数据量
6)删除列操作
编辑
7)删除一个ROWKEY
编辑
8)清空表
1.启动hbase
start-all.sh
zkServer.sh start (所有节点)
start-hbase.sh
stop-hbase.sh
https://img-blog.csdnimg.cn/direct/fa40023d196449ab9f1cabbcceac972f.png
2.进入hbase
hbase shell
quit https://img-blog.csdnimg.cn/direct/3d9d1a2d685749ecba5aef30f17d85f5.png
3.help (查看HBASE SHELL支持的下令)
https://img-blog.csdnimg.cn/direct/bc76997539464b84ac4f955483a2165f.png
Group name: general
Commands: processlist, status, table_help, version, whoami
Group name: ddl
Commands: alter, alter_async, alter_status, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, list_regions, locate_region, show_filters
Group name: namespace
Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables
Group name: dml
Commands: append, count, delete, deleteall, get, get_counter, get_splits, incr, put, scan, truncate, truncate_preserve
4.general (普遍的)
Group name: general
Commands: processlist, status, table_help, version, whoami
查看版本
version
查看HBASE当前版本号
status
https://img-blog.csdnimg.cn/direct/a48655c080eb49f6ad9ed260db272040.png
5.ddl - 表操作
Group name: ddl
Commands: alter, alter_async, alter_status, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, list_regions, locate_region, show_filters
1)create 创建表
样例:
默认命名空间下创建mytb1表 列族为info
create 'mytb1','info'
在db1命名空间下创建表
create_namespace 'db1'
create 'db1:mytb1','info1'
创建表时指定多个列族
create 'db1:mytb2','info1','info2','info3'
创建表并指定列族版本
create 'db1:mytb3',{NAME => 'info1',VERSIONS => 3} https://img-blog.csdnimg.cn/direct/317abe87589b400ab6f919105534f5df.png
https://img-blog.csdnimg.cn/direct/66d01fc2aab44a1f9239241037ef685c.png
t1: 表示表名称
f1: 表示列族
ns1:表示定名空间
Create a table with namespace=ns1 and table qualifier=t1
hbase> create 'ns1:t1', {NAME => 'f1', VERSIONS => 5}
help 'create'
Create a table with namespace=ns1 and table qualifier=t1
hbase> create 'ns1:t1', {NAME => 'f1', VERSIONS => 5}
Create a table with namespace=default and table qualifier=t1
hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}
hbase> # The above in shorthand would be the following:
hbase> create 't1', 'f1', 'f2', 'f3'
hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true}
hbase> create 't1', {NAME => 'f1', CONFIGURATION => {'hbase.hstore.blockingStoreFiles' => '10'}}
Table configuration options can be put at the end.
Examples:
hbase> create 'ns1:t1', 'f1', SPLITS => ['10', '20', '30', '40']
hbase> create 't1', 'f1', SPLITS => ['10', '20', '30', '40']
hbase> create 't1', 'f1', SPLITS_FILE => 'splits.txt', OWNER => 'johndoe'
hbase> create 't1', {NAME => 'f1', VERSIONS => 5}, METADATA => { 'mykey' => 'myvalue' }
hbase> # Optionally pre-split the table into NUMREGIONS, using
hbase> # SPLITALGO ("HexStringSplit", "UniformSplit" or classname)
hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit'}
hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit', REGION_REPLICATION => 2, CONFIGURATION => {'hbase.hregion.scan.loadColumnFamiliesOnDemand' => 'true'}}
hbase> create 't1', {NAME => 'f1', DFS_REPLICATION => 1}
You can also keep around a reference to the created table:
hbase> t1 = create 't1', 'f1'
2)describe 查看表的具体信息
help 'describe'
Describe the named table. For example:
hbase> describe 't1'
hbase> describe 'ns1:t1'
Alternatively, you can use the abbreviated 'desc' for the same thing.
hbase> desc 't1'
hbase> desc 'ns1:t1'
样例:
describe 'db1:mytb2'
表中的列族信息 可以看出 每个列族都维护自己的一个版本信息 一个列族对应一个store
describe 'db1:mytb3'
desc 'db1:mytb3' https://img-blog.csdnimg.cn/direct/1c418561beb041129765c28066269458.png
3)alter 修改表
help 'alter'
hbase> alter 't1', NAME => 'f1', VERSIONS => 5
hbase> alter 'ns1:t1', 'delete' => 'f1'
样例
1.修改列族版本号
alter 'db1:mytb3',NAME => 'info1',VERSIONS => 4
2.删除列族
alter 'db1:mytb2','delete' => 'info3' https://img-blog.csdnimg.cn/direct/dfd5d0a033144b5c982c73db2881d185.png
https://img-blog.csdnimg.cn/direct/b5f8aa8e176448ba967632594da7bd97.png
4)drop 删除表
help 'drop'
Drop the named table. Table must first be disabled:
hbase> drop 't1'
hbase> drop 'ns1:t1'
注意:使用drop操作时 先需要执行disable
help 'disable'
Start disable of named table:
hbase> disable 't1'
hbase> disable 'ns1:t1'
样例:
1.disable 'db1:mytb2'
2.drop'db1:mytb2'
https://img-blog.csdnimg.cn/direct/748e4ce840264e04b21c0189d803ea2f.png
5)关闭及启用表
1.关闭表操作
disable 'db1:mytb1'
desc 'db1:mytb1'
2.启用表操作
enable'db1:mytb1'
desc 'db1:mytb1'
https://img-blog.csdnimg.cn/direct/46adcdf3d1cd4ec2a46183b32b221451.png
6.namespace (定名空间)
Group name: namespace
Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables
1)create_namespace 创建定名空间
help 'create_namespace'
hbase> create_namespace 'ns1'
hbase> create_namespace 'ns1', {'PROPERTY_NAME'=>'PROPERTY_VALUE'}
样例:
create_namespace 'mydb1'
create_namespace 'mydb2',{'create_time' => '2022-04-25'}
https://img-blog.csdnimg.cn/direct/75374169c7df4027bc9f1f2eebf7f145.png
2)list_namespace 查看当前定名空间
样例:list_namespace
结果:
default --用户默认使用的定名空间
hbase --hbase中存放的是HBase内置的表
mydb1 --自己创建的定名空间
https://img-blog.csdnimg.cn/direct/1bc39c1ffc314367a61e78ba48341460.png
3)describe_namespace 查看定名空间的具体信息
help 'describe_namespace'
hbase> describe_namespace 'ns1'
样例:
describe_namespace 'mydb1' https://img-blog.csdnimg.cn/direct/0ab14b3a6fc7474c925e4cf4a2e95f95.png
4)alter_namespace 修改定名空间
help 'alter_namespace'
To add/modify a property:
hbase> alter_namespace 'ns1', {METHOD => 'set', 'PROPERTY_NAME' => 'PROPERTY_VALUE'}
To delete a property:
hbase> alter_namespace 'ns1', {METHOD => 'unset', NAME=>'PROPERTY_NAME'}
样例:
增加author配置并且修改create_time配置
alter_namespace 'mydb2',{METHOD => 'set','author' => 'act','create_time' => '2022-04-25'}
alter_namespace 'mydb2',{'METHOD' => 'set','author' => 'act','create_time' => '2022-04-15'}
删除create_time配置
alter_namespace 'mydb2',{METHOD => 'unset',NAME => 'author'} https://img-blog.csdnimg.cn/direct/3ccc57683fcb410b975fafced86f4f8d.png
https://img-blog.csdnimg.cn/direct/8ac7733d2d074e60a9ae0a74a930b46d.png
https://img-blog.csdnimg.cn/direct/1bc20e411265472390b4baa0def23bab.png
5)drop_namespace 删除空的定名空间
help 'drop_namespace'
Drop the named namespace. The namespace must be empty.
drop_namespace 'mydb2'
https://img-blog.csdnimg.cn/direct/15da150eee4044a4a395f326a6a65846.png
6)list_namespace_tables 查看指定定名空间下的表
help 'list_namespace_tables'
hbase> list_namespace_tables 'ns1'
list_namespace_tables 'default' https://img-blog.csdnimg.cn/direct/b09671e750954a68a01ba5e254e2207e.png
7.dml
1)put 上传及修改数据操作
help 'put'
r1 表示 rowKey
c1 表示 列名称
hbase> put 'ns1:t1', 'r1', 'c1', 'value'
hbase> put 't1', 'r1', 'c1', 'value'
hbase> put 't1', 'r1', 'c1', 'value', ts1
hbase> put 't1', 'r1', 'c1', 'value', {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> put 't1', 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> put 't1', 'r1', 'c1', 'value', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
样例:
create 'db1:stu','info'
list_namespace_tables 'db1'
desc 'db1:stu'
put 'db1:stu','1001','info:name','zhangsan'
注:修改数据可以直接用put上传最新数据进行替换
https://img-blog.csdnimg.cn/direct/7137e4d82b554aaeb3ed409c73b91bb2.png
2)get 获取一行数据操作
help 'get'
hbase> t.get 'r1'
hbase> t.get 'r1', {TIMERANGE => }
hbase> t.get 'r1', {COLUMN => 'c1'}
hbase> t.get 'r1', {COLUMN => ['c1', 'c2', 'c3']}
hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1}
hbase> t.get 'r1', {COLUMN => 'c1', TIMERANGE => , VERSIONS => 4}
hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4}
hbase> t.get 'r1', {FILTER => "ValueFilter(=, 'binary:abc')"}
hbase> t.get 'r1', 'c1'
hbase> t.get 'r1', 'c1', 'c2'
hbase> t.get 'r1', ['c1', 'c2']
hbase> t.get 'r1', {CONSISTENCY => 'TIMELINE'}
hbase> t.get 'r1', {CONSISTENCY => 'TIMELINE', REGION_REPLICA_ID => 1}
get 'db1:stu','1001'
put 'db1:stu','1001','info:age','12'
get 'db1:stu','1001'
获取指定RowKey中某一列数据
get 'db1:stu','1001','info:age'
获取指定RowKey下的多列数据
get 'db1:stu','1001','info:age','info:name' https://img-blog.csdnimg.cn/direct/4f3cdddf26fe4508acab8c3de1b817ca.png
https://img-blog.csdnimg.cn/direct/af32f44d199e4f3eb252573075936f37.png
3)scan 获取表中所有数据
help 'scan'
scan 'db1:stu'
插入多条数据:
put 'db1:stu','1001','info:name','zhjangsan'
put 'db1:stu','1001','info:age','12'
put 'db1:stu','1001','info:clazz','clazz1'
put 'db1:stu','1002','info:name','lisi'
put 'db1:stu','1002','info:age','12'
put 'db1:stu','1002','info:clazz','clazz2'
put 'db1:stu','1003','info:name','wangwu'
put 'db1:stu','1003','info:age','12'
put 'db1:stu','1003','info:clazz','25'
scan 'db1:stu'
put 'db1:stu','2033','info:name','wangwu'
put 'db1:stu','2033','info:age','12'
put 'db1:stu','2033','info:clazz','25'
scan 'db1:stu'
put 'db1:stu','1004','info:name','wangwu'
put 'db1:stu','1004','info:age','12'
put 'db1:stu','1004','info:clazz','25'
scan 'db1:stu'
发现1004在2033前面 所以说rowKey是按照字典顺序排序的
put 'db1:stu','2044','info:name','liliu'
put 'db1:stu','2044','info:age','12'
put 'db1:stu','2044','info:clazz','25'
scan 'db1:stu'
put 'db1:stu','10010','info:name','wan2gwu'
put 'db1:stu','10010','info:age','12'
put 'db1:stu','10010','info:clazz','25'
scan 'db1:stu'
put 'db1:stu','1001$','info:name','zhjangsan'
put 'db1:stu','1001$','info:age','12'
put 'db1:stu','1001$','info:clazz','clazz1'
scan 'db1:stu'
发现10010在1001后面 所以说rowKey是按照字典顺序排序的
ROWKEY是根据字典排序 并且排序的依据是按位比较ASCII码表
https://img-blog.csdnimg.cn/direct/a33df8ce1f564b49adeb29f0d4177063.png
https://img-blog.csdnimg.cn/direct/9269cafac849429db3ccffbcdb686170.png
https://img-blog.csdnimg.cn/direct/c0dcd66afb4b4039990d8b896d328816.png
https://img-blog.csdnimg.cn/direct/9bae9f5bc24c4297b575e0d563cd5c1a.png
help 'scan'
scan 'db1:stu',{LIMIT => 3}
按ROWKEY范围进行取值 左闭右开 取值包含STARTROW 不包含STOPROW
scan 'db1:stu',{STARTROW => '1001',STOPROW => '1004'}
根据ASCII码取值
scan 'db1:stu',{STARTROW => '1001',STOPROW => '1001~'}
scan 'db1:stu',{STARTROW => '1001!',STOPROW => '1001~'}
查看表中所有数据并展示所有版本信息
scan 'db1:stu',{RAW => true,VERSIONS => 10} https://img-blog.csdnimg.cn/direct/0784f8f2ccae47a1846801b822cce540.png
https://img-blog.csdnimg.cn/direct/26bbb2e1554e41b99ad218ad4cbc57e8.png
https://img-blog.csdnimg.cn/direct/a6e823645ab74934931a3d8b1d5fdbd9.png
4)list 查看所有表
list
https://img-blog.csdnimg.cn/direct/165c40b5da6e4445bdf0fe33f16fbb16.png
5)count 统计表中数据量
count 'db1:stu'
https://img-blog.csdnimg.cn/direct/51287a5669784edd8b430d479851d081.png
6)删除列操作
help 'delete'
scan 'db1:stu'
delete 'db1:stu','1001','info:age',时间戳
https://img-blog.csdnimg.cn/direct/93aa90c030c3472b82dbd64d79e83d05.png
7)删除一个ROWKEY
help 'deleteall'
hbase> t.deleteall 'r1'
hbase> t.deleteall 'r1', 'c1'
hbase> t.deleteall 'r1', 'c1', ts1
hbase> t.deleteall 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
deleteall 'db1:stu','1001' https://img-blog.csdnimg.cn/direct/6608c197f509475398c0f0e201acce12.png
8)清空表
help 'truncate'
Disables, drops and recreates the specified table.
样例:
truncate 'db1:stu'
https://img-blog.csdnimg.cn/direct/dbf4d6870e814ea6922a77f342b2d5f1.png
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]