1.声明

当前内容主要用于本人学习和复习,当前内容为HBase中的QuickStart中使用HBase Shell的操作

当前内容基于博文:HBase的安装和启动

2.使用HBase SHell实现操作

查看是否启动成功(显示HMaster就表示单机模式启动成功)

hbase 如何判断是否启动 hbase中查看表状态是否启用_表名


1.连接本地的HBase

./bin/hbase shell

hbase 如何判断是否启动 hbase中查看表状态是否启用_后缀_02


显示结果中说明了,没有启动本地的Hadoop库,使用了builtin-java的类

可以使用help查看shell命令帮助

可以使用exit退出shell

2.查看帮助

help

hbase 如何判断是否启动 hbase中查看表状态是否启用_后缀_03


3.create命令

Use the create command to create a new table. You must specify the table name and the ColumnFamily name.

使用create命令去创建一个新表,你必须使用特殊的表名和列族名

create 'test','cf'

意思就是创建表test以及创建列族为cf

hbase 如何判断是否启动 hbase中查看表状态是否启用_后缀_04

4.list命令
List Information About your Table
列出你的表的信息
Use the list command to confirm your table exists
使用list命令去告诉你表是否存在

list 'test'
list 'te'

hbase 如何判断是否启动 hbase中查看表状态是否启用_hbase 如何判断是否启动_05


当使用list列出一个不存在的结果,那么返回的结果rows就是0(可以通过list检查当前的table是否存在)

Now use the describe command to see details, including configuration default

显示使用describe命令去显示详情,包括默认的配置

describe 'test'

hbase 如何判断是否启动 hbase中查看表状态是否启用_表名_06

5.put命令
To put data into your table, use the put command.
使用put命令向当前table中添加数据

put 'test', 'row1', 'cf:a', 'value1'
put 'test', 'row2', 'cf:b', 'value2'
put 'test', 'row3', 'cf:c', 'value3'

put 数据表,行名,列族:后缀,值

hbase 如何判断是否启动 hbase中查看表状态是否启用_后缀_07


Here, we insert three values, one at a time. The first insert is at row1, column cf:a, with a value of value1. Columns in HBase are comprised of a column family prefix, cf in this example, followed by a colon and then a column qualifier suffix, a in this case.

这里,我们一次性插入了三个值。这提一个插入的在row1,列cf:a,使用值value1.HBase中的列由一个列系列前缀(在本例中为cf)组成,后跟一个冒号,然后是一个列限定符后缀(在本例中为a)。

也就是说,当前添加的列实际上就是前面创建的列族前缀+冒号:+后缀方式

6.scan命令
Scan the table for all data at once.
一次性扫描表中的所有数据,使用scan

scan 'test'

hbase 如何判断是否启动 hbase中查看表状态是否启用_表名_08

7.get命令
Get a single row of data.
获取单行数据

get 'test','row1'

get 数据表,行

hbase 如何判断是否启动 hbase中查看表状态是否启用_Shell_09

8.disable和enable命令
禁用表
If you want to delete a table or change its settings, as well as in some other situations, you need to disable the table first, using the disable command. You can re-enable it using the enable command
如果你想要删除表或者改变它的设置,以及在其他情况下,你需要在第一时间禁用表,使用disable命令。你还可以使用enable命令重新启用表

disable 'test'
enable 'test'

hbase 如何判断是否启动 hbase中查看表状态是否启用_hbase 如何判断是否启动_10

9.删除表

disable 'test'
drop 'test'
list 'test'

hbase 如何判断是否启动 hbase中查看表状态是否启用_hbase 如何判断是否启动_11


10.退出hbase的shell

To exit the HBase Shell and disconnect from your cluster, use the quit command. HBase is still running in the background.

退出HBase Shell和断开你的集群连接,使用quit命令,HBase任然在后台运行

quit

hbase 如何判断是否启动 hbase中查看表状态是否启用_Shell_12

11.停止HBase

./bin/stop-hbase.sh

hbase 如何判断是否启动 hbase中查看表状态是否启用_后缀_13

3.总结

1.创建表的时候需要指定表名和列族名称,使用逗号分隔

2.通过bin/start-hbase.sh启动HBase和使用bin/stop-hbase.sh停止HBase

3.添加数据时需要使用put方法,并指定表名,行名,列族:列,值方式添加数据,注意列实际为列族+冒号+列方式

4.删除当前的数据表的之前需要先禁用当前的表