0


HBASE SHELL学习

HBASE SHELL学习

小白的Hbase学习笔记

1.启动hbase

  1. start-all.sh
  2. zkServer.sh start (所有节点)
  3. start-hbase.sh
  4. stop-hbase.sh

2.进入hbase

  1. hbase shell
  2. quit

3.help (查看HBASE SHELL支持的命令)

  1. Group name: general
  2. Commands: processlist, status, table_help, version, whoami
  3. Group name: ddl
  4. 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
  5. Group name: namespace
  6. Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables
  7. Group name: dml
  8. Commands: append, count, delete, deleteall, get, get_counter, get_splits, incr, put, scan, truncate, truncate_preserve

4.general (普遍的)

  1. Group name: general
  2. Commands: processlist, status, table_help, version, whoami

查看版本

version

查看HBASE当前版本号

status

5.ddl - 表操作

  1. Group name: ddl
  2. 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 创建表
  1. 样例:
  2. 默认命名空间下创建mytb1 列族为info
  3. create 'mytb1','info'
  4. db1命名空间下创建表
  5. create_namespace 'db1'
  6. create 'db1:mytb1','info1'
  7. 创建表时指定多个列族
  8. create 'db1:mytb2','info1','info2','info3'
  9. 创建表并指定列族版本
  10. create 'db1:mytb3',{NAME => 'info1',VERSIONS => 3}

t1: 表示表名称

f1: 表示列族

ns1:表示命名空间

Create a table with namespace=ns1 and table qualifier=t1
hbase> create 'ns1:t1', {NAME => 'f1', VERSIONS => 5}

  1. help 'create'
  2. Create a table with namespace=ns1 and table qualifier=t1
  3. hbase> create 'ns1:t1', {NAME => 'f1', VERSIONS => 5}
  4. Create a table with namespace=default and table qualifier=t1
  5. hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}
  6. hbase> # The above in shorthand would be the following:
  7. hbase> create 't1', 'f1', 'f2', 'f3'
  8. hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true}
  9. hbase> create 't1', {NAME => 'f1', CONFIGURATION => {'hbase.hstore.blockingStoreFiles' => '10'}}
  10. Table configuration options can be put at the end.
  11. Examples:
  12. hbase> create 'ns1:t1', 'f1', SPLITS => ['10', '20', '30', '40']
  13. hbase> create 't1', 'f1', SPLITS => ['10', '20', '30', '40']
  14. hbase> create 't1', 'f1', SPLITS_FILE => 'splits.txt', OWNER => 'johndoe'
  15. hbase> create 't1', {NAME => 'f1', VERSIONS => 5}, METADATA => { 'mykey' => 'myvalue' }
  16. hbase> # Optionally pre-split the table into NUMREGIONS, using
  17. hbase> # SPLITALGO ("HexStringSplit", "UniformSplit" or classname)
  18. hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit'}
  19. hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit', REGION_REPLICATION => 2, CONFIGURATION => {'hbase.hregion.scan.loadColumnFamiliesOnDemand' => 'true'}}
  20. hbase> create 't1', {NAME => 'f1', DFS_REPLICATION => 1}
  21. You can also keep around a reference to the created table:
  22. hbase> t1 = create 't1', 'f1'
2)describe 查看表的具体信息
  1. help 'describe'
  2. Describe the named table. For example:
  3. hbase> describe 't1'
  4. hbase> describe 'ns1:t1'
  5. Alternatively, you can use the abbreviated 'desc' for the same thing.
  6. hbase> desc 't1'
  7. hbase> desc 'ns1:t1'
  8. 样例:
  9. describe 'db1:mytb2'
  10. 表中的列族信息 可以看出 每个列族都维护自己的一个版本信息 一个列族对应一个store
  11. describe 'db1:mytb3'
  12. desc 'db1:mytb3'

3)alter 修改表
  1. help 'alter'
  2. hbase> alter 't1', NAME => 'f1', VERSIONS => 5
  3. hbase> alter 'ns1:t1', 'delete' => 'f1'
  4. 样例
  5. 1.修改列族版本号
  6. alter 'db1:mytb3',NAME => 'info1',VERSIONS => 4
  7. 2.删除列族
  8. alter 'db1:mytb2','delete' => 'info3'

4)drop 删除表
  1. help 'drop'
  2. Drop the named table. Table must first be disabled:
  3. hbase> drop 't1'
  4. hbase> drop 'ns1:t1'
  5. 注意:使用drop操作时 先需要执行disable
  6. help 'disable'
  7. Start disable of named table:
  8. hbase> disable 't1'
  9. hbase> disable 'ns1:t1'
  10. 样例:
  11. 1.disable 'db1:mytb2'
  12. 2.drop'db1:mytb2'

5)关闭及启用表
  1. 1.关闭表操作
  2. disable 'db1:mytb1'
  3. desc 'db1:mytb1'
  4. 2.启用表操作
  5. enable'db1:mytb1'
  6. desc 'db1:mytb1'

6.namespace (命名空间)

  1. Group name: namespace
  2. Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables
1)create_namespace 创建命名空间
  1. help 'create_namespace'
  2. hbase> create_namespace 'ns1'
  3. hbase> create_namespace 'ns1', {'PROPERTY_NAME'=>'PROPERTY_VALUE'}
  4. 样例:
  5. create_namespace 'mydb1'
  6. create_namespace 'mydb2',{'create_time' => '2022-04-25'}
2)list_namespace 查看当前命名空间

样例:list_namespace

结果:

default --用户默认使用的命名空间

hbase --hbase中存放的是HBase内置的表

mydb1 --自己创建的命名空间

3)describe_namespace 查看命名空间的详细信息
  1. help 'describe_namespace'
  2. hbase> describe_namespace 'ns1'
  3. 样例:
  4. describe_namespace 'mydb1'

4)alter_namespace 修改命名空间
  1. help 'alter_namespace'
  2. To add/modify a property:
  3. hbase> alter_namespace 'ns1', {METHOD => 'set', 'PROPERTY_NAME' => 'PROPERTY_VALUE'}
  4. To delete a property:
  5. hbase> alter_namespace 'ns1', {METHOD => 'unset', NAME=>'PROPERTY_NAME'}
  6. 样例:
  7. 增加author配置并且修改create_time配置
  8. alter_namespace 'mydb2',{METHOD => 'set','author' => 'act','create_time' => '2022-04-25'}
  9. alter_namespace 'mydb2',{'METHOD' => 'set','author' => 'act','create_time' => '2022-04-15'}
  10. 删除create_time配置
  11. alter_namespace 'mydb2',{METHOD => 'unset',NAME => 'author'}

5)drop_namespace 删除空的命名空间
  1. help 'drop_namespace'
  2. Drop the named namespace. The namespace must be empty.
  3. drop_namespace 'mydb2'
6)list_namespace_tables 查看指定命名空间下的表
  1. help 'list_namespace_tables'
  2. hbase> list_namespace_tables 'ns1'
  3. list_namespace_tables 'default'

7.dml

1)put 上传及修改数据操作
  1. help 'put'
  2. r1 表示 rowKey
  3. c1 表示 列名称
  4. hbase> put 'ns1:t1', 'r1', 'c1', 'value'
  5. hbase> put 't1', 'r1', 'c1', 'value'
  6. hbase> put 't1', 'r1', 'c1', 'value', ts1
  7. hbase> put 't1', 'r1', 'c1', 'value', {ATTRIBUTES=>{'mykey'=>'myvalue'}}
  8. hbase> put 't1', 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
  9. hbase> put 't1', 'r1', 'c1', 'value', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
  10. 样例:
  11. create 'db1:stu','info'
  12. list_namespace_tables 'db1'
  13. desc 'db1:stu'
  14. put 'db1:stu','1001','info:name','zhangsan'
  15. 注:修改数据可以直接用put上传最新数据进行替换

2)get 获取一行数据操作
  1. help 'get'
  2. hbase> t.get 'r1'
  3. hbase> t.get 'r1', {TIMERANGE => [ts1, ts2]}
  4. hbase> t.get 'r1', {COLUMN => 'c1'}
  5. hbase> t.get 'r1', {COLUMN => ['c1', 'c2', 'c3']}
  6. hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1}
  7. hbase> t.get 'r1', {COLUMN => 'c1', TIMERANGE => [ts1, ts2], VERSIONS => 4}
  8. hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4}
  9. hbase> t.get 'r1', {FILTER => "ValueFilter(=, 'binary:abc')"}
  10. hbase> t.get 'r1', 'c1'
  11. hbase> t.get 'r1', 'c1', 'c2'
  12. hbase> t.get 'r1', ['c1', 'c2']
  13. hbase> t.get 'r1', {CONSISTENCY => 'TIMELINE'}
  14. hbase> t.get 'r1', {CONSISTENCY => 'TIMELINE', REGION_REPLICA_ID => 1}
  15. get 'db1:stu','1001'
  16. put 'db1:stu','1001','info:age','12'
  17. get 'db1:stu','1001'
  18. 获取指定RowKey中某一列数据
  19. get 'db1:stu','1001','info:age'
  20. 获取指定RowKey下的多列数据
  21. get 'db1:stu','1001','info:age','info:name'

3)scan 获取表中所有数据
  1. help 'scan'
  2. scan 'db1:stu'
  3. 插入多条数据:
  4. put 'db1:stu','1001','info:name','zhjangsan'
  5. put 'db1:stu','1001','info:age','12'
  6. put 'db1:stu','1001','info:clazz','clazz1'
  7. put 'db1:stu','1002','info:name','lisi'
  8. put 'db1:stu','1002','info:age','12'
  9. put 'db1:stu','1002','info:clazz','clazz2'
  10. put 'db1:stu','1003','info:name','wangwu'
  11. put 'db1:stu','1003','info:age','12'
  12. put 'db1:stu','1003','info:clazz','25'
  13. scan 'db1:stu'
  14. put 'db1:stu','2033','info:name','wangwu'
  15. put 'db1:stu','2033','info:age','12'
  16. put 'db1:stu','2033','info:clazz','25'
  17. scan 'db1:stu'
  18. put 'db1:stu','1004','info:name','wangwu'
  19. put 'db1:stu','1004','info:age','12'
  20. put 'db1:stu','1004','info:clazz','25'
  21. scan 'db1:stu'
  22. 发现10042033前面 所以说rowKey是按照字典顺序排序的
  23. put 'db1:stu','2044','info:name','liliu'
  24. put 'db1:stu','2044','info:age','12'
  25. put 'db1:stu','2044','info:clazz','25'
  26. scan 'db1:stu'
  27. put 'db1:stu','10010','info:name','wan2gwu'
  28. put 'db1:stu','10010','info:age','12'
  29. put 'db1:stu','10010','info:clazz','25'
  30. scan 'db1:stu'
  31. put 'db1:stu','1001$','info:name','zhjangsan'
  32. put 'db1:stu','1001$','info:age','12'
  33. put 'db1:stu','1001$','info:clazz','clazz1'
  34. scan 'db1:stu'
  35. 发现100101001后面 所以说rowKey是按照字典顺序排序的
  36. ROWKEY是根据字典排序 并且排序的依据是按位比较ASCII码表

  1. help 'scan'
  2. scan 'db1:stu',{LIMIT => 3}
  3. ROWKEY范围进行取值 左闭右开 取值包含STARTROW 不包含STOPROW
  4. scan 'db1:stu',{STARTROW => '1001',STOPROW => '1004'}
  5. 根据ASCII码取值
  6. scan 'db1:stu',{STARTROW => '1001',STOPROW => '1001~'}
  7. scan 'db1:stu',{STARTROW => '1001!',STOPROW => '1001~'}
  8. 查看表中所有数据并展示所有版本信息
  9. scan 'db1:stu',{RAW => true,VERSIONS => 10}

4)list 查看所有表

list

5)count 统计表中数据量

count 'db1:stu'

6)删除列操作
  1. help 'delete'
  2. scan 'db1:stu'
  3. delete 'db1:stu','1001','info:age',时间戳
7)删除一个ROWKEY
  1. help 'deleteall'
  2. hbase> t.deleteall 'r1'
  3. hbase> t.deleteall 'r1', 'c1'
  4. hbase> t.deleteall 'r1', 'c1', ts1
  5. hbase> t.deleteall 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
  6. deleteall 'db1:stu','1001'
8)清空表
  1. help 'truncate'
  2. Disables, drops and recreates the specified table.
  3. 样例:
  4. truncate 'db1:stu'

标签: hbase 学习 数据库

本文转载自: https://blog.csdn.net/2301_77836489/article/details/139194885
版权归原作者 难以触及的高度 所有, 如有侵权,请联系我们删除。

“HBASE SHELL学习”的评论:

还没有评论