Hbase操作语句备份

Hbase操作参考网络教程:http://www.yiibai.com/hbase/hbase_describe_and_alter.html

 

1、命名空间管理

系统预定义命名空间:

hbase :系统命名空间,存放Hbase的内部表

default:建表时未指定命名空间时,使用此命名空间

2、Connect to HBase.

Connect to your running instance of HBase using the hbase shell command, located in the bin/directory of your HBase install. In this example, some usage and version information that is printed when you start HBase Shell has been omitted. The HBase Shell prompt ends with a > character.

$ ./bin/hbase shell
hbase(main):001:0>

 3、Display HBase Shell Help Text.

Type help and press Enter, to display some basic usage information for HBase Shell, as well as several example commands. Notice that table names, rows, columns all must be enclosed in quote characters.

 4、Create a table.

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

hbase(main):001:0> create 'test', 'cf' 
0 row(s) in 0.4170 seconds

=> Hbase::Table - test

 5、List Information About your Table

 Use the list command to 

hbase(main):002:0> list 'test' 
TABLE 
test 
1 row(s) in 0.0180 seconds 

=> ["test"]

 6、Put data into your table.

To put data into your table, use the put command.

hbase(main):003:0> put 'test', 'row1', 'cf:a', 'value1' 
0 row(s) in 0.0850 seconds

hbase(main):004:0> put 'test', 'row2', 'cf:b', 'value2'
0 row(s) in 0.0110 seconds

hbase(main):005:0> put 'test', 'row3', 'cf:c', 'value3'
0 row(s) in 0.0100 seconds

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.

7、Scan the table for all data at once.

One of the ways to get data from HBase is to scan. Use the scan command to scan the table for data. You can limit your scan, but for now, all data is fetched.

hbase(main):006:0> scan 'test'
ROW                                      COLUMN+CELL
 row1                                    column=cf:a, timestamp=1421762485768, value=value1
 row2                                    column=cf:b, timestamp=1421762491785, value=value2
 row3                                    column=cf:c, timestamp=1421762496210, value=value3
3 row(s) in 0.0230 seconds

8、Get a single row of data.

To get a single row of data at a time, use the get command. 

hbase(main):007:0> get 'test', 'row1'
COLUMN                                   CELL
 cf:a                                    timestamp=1421762485768, value=value1
1 row(s) in 0.0350 seconds

9、Disable a table.

 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.  

hbase(main):008:0> disable 'test'
0 row(s) in 1.1820 seconds

hbase(main):009:0> enable 'test'
0 row(s) in 0.1770 seconds

Disable the table again if you tested the enable command above: 

hbase(main):010:0> disable 'test'
0 row(s) in 1.1820 seconds

10、Drop the table. 

To drop (delete) a table, use the drop command. 

hbase(main):011:0> drop 'test'
0 row(s) in 0.1370 seconds

11、Exit the HBase Shell.

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

 12、描述表信息

describe  ‘表名’

 13、其他

对于建表,和RDBMS类似,HBase也有namespace的概念,可以指定表空间创建表,也可以直接创建表,进入default表空间。

对于数据操作,HBase支持四类主要的数据操作,分别是:

Put :增加一行,修改一行;

Delete :删除一行,删除指定列族,删除指定column的多个版本,删除指定column的制定版本等;

Get :获取指定行的所有信息,获取指定行和指定列族的所有colunm,获取指定column,获取指定column的几个版本, 获取指定
column的指定版本等;
Scan :获取所有行,获取指定行键范围的行,获取从某行开始的几行,获取满足过滤条件的行等。

 

#创建一个多列簇的表
create 'stu1' ,'course','grade'

#新增数据
     表名    行号     列簇中的列       列值
put 'stu1' ,'stu1' ,'course:math'     ,'50'
put 'stu1' ,'stu1' ,'course:English'  ,'80'
put 'stu1' ,'stu1' ,'grade:highlevel' ,'1'
put 'stu1' ,'stu2' ,'grade:highlevel' ,'2'
put 'stu1' ,'stu2' ,'course:English'  ,'90'

#更新记录
put 'stu1' ,'stu2','course:English','900'


#读取指定数据
     表名   行号        指定列  
get 'stu1' ,'stu2',{COLUMN=>'course:English'}
     表名   行号    指定列簇   
get 'stu1' ,'stu2','course'
     表名   行号     
get 'stu1' ,'stu2'

 

posted @ 2016-11-23 10:30  saratearing  阅读(194)  评论(0)    收藏  举报