2.1 HBase安装部署

2.1.1 ZooKeeper安装

2.1.2 Hadoop安装

2.1.3 HBase安装

(1)下载解压

(2)配置文件

(3)启动


2.2 HBase Shell操作

2.2.1 基本操作

(1)进入HBase客户端命令行

  1. bin/hbase shell

(2)查看帮助命令

help

(3)查看当前数据库中有哪些表

list # 只列出用户表,不包括系统表

注意事项:

  1. hbase shell中,输入命令时如果出错,希望删除,此时按“backspace”删除的是当前光标后面的字符,按“delete”或“shift+backspace”删除的才是当前光标前的字符。
  2. hbase shell中,输入命令后,不用添加“;”,如果添加了,回车,会进入多行输入模式。若想退出,则可连续输入“单引号+回车”。

(4)命令分类

  • general:通用类命令。
  • ddl:操作表的命令。
  • namespace:操作命名空间的命令。
  • dml:操作数据的命令。
  • tools:运维工具。
  • replication:数据复制命令。
  • snapshots:快照命令。
  • configuration:配置命令。
  • ……

    2.2.2 表的基本操作——DDL

    (1)创建表

    ```shell create ‘student’,’info’

    在default命名空间下,创建名为student的表,有一个名为info的列族

create ‘stu’,’info1’,’info2’

在default命名空间下,创建名为stu的表,有两个列族info1和info2

<a name="EwmeJ"></a>
#### (2)查询表
```shell
list # 列出所有用户表

describe 'student' # 查看student表详情

表详情中列出了各个列族的详情(COLUMN FAMILIES DESCRIPTION),其中值得注意的属性有:

  • BLOOMFILTER:布隆过滤器。默认为’row’。
  • VERSION:单元格中保存的最近的版本数量,默认为1。
  • TTL:数据保存时间。默认FOREVER,即永不删除。

    (3)删除表

    disable 'student' # 先disable表student
    drop 'student'    # 再删除表student
    

    (4)修改表

    alter 'student',{NAME=>'info',VERSION=>3}
    # 修改student表info列族的VERSION属性
    

    2.2.3 命名空间的基本操作

    ```shell

    list_namespace

create_namespace ‘bigdata’

在指定命名空间下建表

create “bigdata:stu”,”info”

删除命名空间

drop_namespace ‘bigdata’ # 必须先删除命名空间下的所有表,才能删除该命名空间

<a name="bkfOC"></a>
## 2.2.4 数据的基本操作——DML
<a name="hNu9u"></a>
#### (1)插入/更新数据
```shell
# 格式
put '<命名空间>:<表名>', '<RowKey>', '<列族>:<列标识符>', '<值>', '<时间戳,可选>', '其他可选参数'

# 实例
put 'stu','1001','info1:name','zhangsan'

(2)查询数据

# scan格式
scan '<命名空间>:<表名>' # 全表全字段扫描
scan '<命名空间>:<表名>' {COLUMNS => ['c1','c2'], LIMIT => 10, STARTROW => 'xyz'} # 带条件扫描
...
# get格式
get '<命名空间>:<表名>', '<RowKey>'
get '<命名空间>:<表名>', '<RowKey>', '<列族>'
get '<命名空间>:<表名>', '<RowKey>', '<列族>:<列标识符>'
...

(3)删除数据

# 删除某个列
delete '<命名空间>:<表名>', '<RowKey>', '<列族>:<列标识符>', '<时间戳,可选>'

# 删除某行
deleteall '<命名空间>:<表名>', '<RowKey>', '<时间戳,可选>'

# 清空整个表
truncate '<命名空间>:<表名>'