hbase操作

名称
命令表达式

创建表
create ‘表名称‘,‘列簇名称1‘,‘列簇名称2‘.......

添加记录
put ‘表名称‘, ‘行名称‘,‘列簇名称:‘,‘值‘

查看记录
get ‘表名称‘,‘行名称‘

查看表中的记录总数
count ‘表名称‘

删除记录
delete ‘表名‘,行名称‘,‘列簇名称‘

删除表
①disable ‘表名称‘ ②drop ‘表名称‘

查看所有记录
scan ‘表名称‘

查看某个表某个列中所有数据
scan ‘表名称‘,[‘列簇名称:‘]

更新记录
即重写一遍进行覆盖

hbase(main):050:0> create ‘ddl‘, ‘id‘, ‘info‘

0 row(s) in 0.0680 seconds

hbase(main):050:0> is_enabled ‘ddl‘
false
0 row(s) in 0.0680 seconds
hbase(main):051:0> enable ‘ddl‘
0 row(s) in 0.6200 seconds
hbase(main):052:0> count ‘ddl‘
0 row(s) in 0.0380 seconds
=> 0
hbase(main):053:0> put ‘ddl‘, ‘example‘, ‘info:age‘, ‘22‘
0 row(s) in 0.0340 seconds
hbase(main):054:0> count ‘ddl‘
1 row(s) in 0.0290 seconds
=> 1
hbase(main):055:0> get ‘ddl‘ , ‘example‘
COLUMN                                               CELL
info:age                                            timestamp=1436785857172, value=22
1 row(s) in 0.0170 seconds
hbase(main):056:0> describe ‘ddl‘
DESCRIPTION                                                                                                                           ENABLED
‘ddl‘, {NAME => ‘info‘, BLOOMFILTER => ‘ROW‘, VERSIONS => ‘1‘, IN_MEMORY => ‘false‘, KEEP_DELETED_CELLS => ‘false‘, DATA_BLOCK_ENCOD true
ING => ‘NONE‘, TTL => ‘FOREVER‘, COMPRESSION => ‘NONE‘, MIN_VERSIONS => ‘0‘, BLOCKCACHE => ‘true‘, BLOCKSIZE => ‘65536‘, REPLICATION
_SCOPE => ‘0‘}
1 row(s) in 0.0630 seconds

hbase(main):057:0> put ‘ddl‘, ‘example‘, ‘info:birthday‘, ‘1999-09-09‘
0 row(s) in 0.0210 seconds
hbase(main):058:0> get ‘ddl‘, ‘example‘
COLUMN                                               CELL
info:age                                            timestamp=1436785857172, value=22
info:birthday                                       timestamp=1436785968230, value=1999-09-09
2 row(s) in 0.0160 seconds

hbase(main):059:0> put ‘ddl‘, ‘example‘, ‘info:company‘, ‘taobao‘
0 row(s) in 0.0230 seconds
hbase(main):060:0> get ‘ddl‘, ‘example‘
COLUMN                                               CELL
info:age                                            timestamp=1436785857172, value=22
info:birthday                                       timestamp=1436785968230, value=1999-09-09
info:company                                        timestamp=1436786030921, value=taobao
3 row(s) in 0.0340 seconds

hbase(main):063:0> put ‘ddl‘, ‘taobao‘, ‘info:age‘, ‘88‘
0 row(s) in 0.0240 seconds
hbase(main):064:0> get ‘ddl‘, ‘taobao‘
COLUMN                                               CELL
info:age                                            timestamp=1436786189132, value=88
1 row(s) in 0.0180 seconds

hbase(main):065:0> put ‘ddl‘, ‘taobao‘, ‘info:addres‘, ‘china‘
0 row(s) in 0.0210 seconds
hbase(main):066:0> get ‘ddl‘, ‘taobao‘
COLUMN                                               CELL
info:addres                                         timestamp=1436786262126, value=china
info:age                                            timestamp=1436786189132, value=88
2 row(s) in 0.0180 seconds
hbase(main):067:0> put ‘ddl‘ , ‘taobao‘, ‘info:birthday‘, ‘2001-01-01‘
0 row(s) in 0.0260 seconds
hbase(main):068:0> get ‘ddl‘, ‘taobao‘
COLUMN                                               CELL
info:addres                                         timestamp=1436786262126, value=china
info:age                                            timestamp=1436786189132, value=88
info:birthday                                       timestamp=1436786301656, value=2001-01-01
3 row(s) in 0.0270 seconds
hbase(main):069:0> put ‘ddl‘, ‘taobao‘, ‘info:compayn‘, ‘alibaba‘
0 row(s) in 0.0400 seconds
hbase(main):070:0> get ‘ddl‘, ‘taobao‘
COLUMN                                               CELL
info:addres                                         timestamp=1436786262126, value=china
info:age                                            timestamp=1436786189132, value=88
info:birthday                                       timestamp=1436786301656, value=2001-01-01
info:compayn                                        timestamp=1436786328287, value=alibaba
4 row(s) in 0.0200 seconds

hbase(main):071:0> get ‘ddl‘, ‘example‘
COLUMN                                               CELL
info:address                                        timestamp=1436786098272, value=china
info:age                                            timestamp=1436785857172, value=22
info:birthday                                       timestamp=1436785968230, value=1999-09-09
info:company                                        timestamp=1436786030921, value=taobao
4 row(s) in 0.0170 seconds
获取一个id的所有数据:
hbase(main):072:0> get ‘ddl‘, ‘taobao‘
COLUMN                                               CELL
info:addres                                         timestamp=1436786262126, value=china
info:age                                            timestamp=1436786189132, value=88
info:birthday                                       timestamp=1436786301656, value=2001-01-01
info:compayn                                        timestamp=1436786328287, value=alibaba
4 row(s) in 0.0240 seconds

获取一个id, 一个列簇的所有数据:
hbase(main):073:0> get ‘ddl‘, ‘taobao‘, ‘info‘
COLUMN                                               CELL
info:addres                                         timestamp=1436786262126, value=china
info:age                                            timestamp=1436786189132, value=88
info:birthday                                       timestamp=1436786301656, value=2001-01-01
info:compayn                                        timestamp=1436786328287, value=alibaba
4 row(s) in 0.0210 seconds
获取一个id的一个列簇中的一个列的所有数据:
hbase(main):074:0> get ‘ddl‘, ‘taobao‘, ‘info:age‘
COLUMN                                               CELL
info:age                                            timestamp=1436786189132, value=88
1 row(s) in 0.0230 seconds

更新一条数据:

hbase(main):076:0> put ‘ddl‘, ‘example‘, ‘info:age‘, ‘66‘
0 row(s) in 0.0250 seconds
hbase(main):077:0> get ‘ddl‘, ‘example‘
COLUMN                                               CELL
info:address                                        timestamp=1436786098272, value=china
info:age                                            timestamp=1436786652004, value=66
info:birthday                                       timestamp=1436785968230, value=1999-09-09
info:company                                        timestamp=1436786030921, value=taobao
4 row(s) in 0.0230 seconds

更新记录:

hbase(main):006:0> get ‘ddl‘, ‘example‘
COLUMN                                               CELL
info:address                                        timestamp=1436786098272, value=china
info:age                                            timestamp=1436786652004, value=66
info:birthday                                       timestamp=1436785968230, value=1999-09-09
info:company                                        timestamp=1436786030921, value=taobao
4 row(s) in 0.0590 seconds
hbase(main):007:0> put ‘ddl‘, ‘example‘, ‘info:age‘, ‘22‘
0 row(s) in 0.1020 seconds
hbase(main):008:0> get ‘ddl‘,‘example‘
COLUMN                                               CELL
info:address                                        timestamp=1436786098272, value=china
info:age                                            timestamp=1436787030235, value=22
info:birthday                                       timestamp=1436785968230, value=1999-09-09
info:company                                        timestamp=1436786030921, value=taobao
4 row(s) in 0.0310 seconds
hbase(main):009:0> get ‘ddl‘, ‘example‘, {COLUMN=>‘info:age‘, TIMESTAMP=>1436786652004}
COLUMN                                               CELL
info:age                                            timestamp=1436786652004, value=66
1 row(s) in 0.0240 seconds
hbase(main):010:0> get ‘ddl‘, ‘example‘, {COLUMN=>‘info:age‘, TIMESTAMP=>1436787030235}
COLUMN                                               CELL
info:age                                            timestamp=1436787030235, value=22
1 row(s) in 0.0080 seconds

hbase(main):011:0> scan ‘ddl‘
ROW                                                  COLUMN+CELL
example                                             column=info:address, timestamp=1436786098272, value=china
example                                             column=info:age, timestamp=1436787030235, value=22
example                                             column=info:birthday, timestamp=1436785968230, value=1999-09-09
example                                             column=info:company, timestamp=1436786030921, value=taobao
taobao                                              column=info:addres, timestamp=1436786262126, value=china
taobao                                              column=info:age, timestamp=1436786189132, value=88
taobao                                              column=info:birthday, timestamp=1436786301656, value=2001-01-01
taobao                                              column=info:compayn, timestamp=1436786328287, value=alibaba
2 row(s) in 0.0560 seconds

hbase(main):015:0> delete ‘ddl‘, ‘example‘, ‘info:age‘
0 row(s) in 0.0750 seconds
hbase(main):016:0> get ‘ddl‘, ‘example‘
COLUMN                                               CELL
info:address                                        timestamp=1436786098272, value=china
info:birthday                                       timestamp=1436785968230, value=1999-09-09
info:company                                        timestamp=1436786030921, value=taobao
3 row(s) in 0.0210 seconds

删除整行数据:

hbase(main):019:0> scan ‘ddl‘
ROW                                                  COLUMN+CELL
example                                             column=info:address, timestamp=1436786098272, value=china
example                                             column=info:birthday, timestamp=1436785968230, value=1999-09-09
example                                             column=info:company, timestamp=1436786030921, value=taobao
taobao                                              column=info:addres, timestamp=1436786262126, value=china
taobao                                              column=info:age, timestamp=1436786189132, value=88
taobao                                              column=info:birthday, timestamp=1436786301656, value=2001-01-01
taobao                                              column=info:compayn, timestamp=1436786328287, value=alibaba
2 row(s) in 0.0460 seconds
hbase(main):020:0> deleteall ‘ddl‘, ‘taobao‘
0 row(s) in 0.0300 seconds
hbase(main):021:0> scan ‘ddl‘
ROW                                                  COLUMN+CELL
example                                             column=info:address, timestamp=1436786098272, value=china
example                                             column=info:birthday, timestamp=1436785968230, value=1999-09-09
example                                             column=info:company, timestamp=1436786030921, value=taobao
1 row(s) in 0.0300 seconds

给example增加‘info:age‘字段,并且使用counter实现递增:

hbase(main):022:0> incr ‘ddl‘, ‘example‘, ‘info:age‘
0 row(s) in 0.0330 seconds
hbase(main):023:0> scan ‘ddl‘
ROW                                                  COLUMN+CELL
example                                             column=info:address, timestamp=1436786098272, value=china
example                                             column=info:age, timestamp=1436787516930, value=\x00\x00\x00\x00\x00\x00\x00\x01
example                                             column=info:birthday, timestamp=1436785968230, value=1999-09-09
example                                             column=info:company, timestamp=1436786030921, value=taobao
1 row(s) in 0.0290 seconds
hbase(main):024:0> incr ‘ddl‘, ‘example‘, ‘info:age‘
0 row(s) in 0.0260 seconds
hbase(main):025:0> scan ‘ddl‘
ROW                                                  COLUMN+CELL
example                                             column=info:address, timestamp=1436786098272, value=china
example                                             column=info:age, timestamp=1436787556057, value=\x00\x00\x00\x00\x00\x00\x00\x02
example                                             column=info:birthday, timestamp=1436785968230, value=1999-09-09
example                                             column=info:company, timestamp=1436786030921, value=taobao
1 row(s) in 0.0770 seconds
hbase(main):026:0> incr ‘ddl‘, ‘example‘, ‘info:age‘
0 row(s) in 0.0130 seconds
hbase(main):027:0> scan ‘ddl‘
ROW                                                  COLUMN+CELL
example                                             column=info:address, timestamp=1436786098272, value=china
example                                             column=info:age, timestamp=1436787562408, value=\x00\x00\x00\x00\x00\x00\x00\x03
example                                             column=info:birthday, timestamp=1436785968230, value=1999-09-09
example                                             column=info:company, timestamp=1436786030921, value=taobao
1 row(s) in 0.0170 seconds

获取当前count值:

hbase(main):041:0> get_counter ‘ddl‘, ‘example‘, ‘info:age‘, ‘dummy
COUNTER VALUE = 3
hbase(main):042:0> get ‘ddl‘, ‘example‘, ‘info:age‘
COLUMN                                               CELL
info:age                                            timestamp=1436787562408, value=\x00\x00\x00\x00\x00\x00\x00\x03
1 row(s) in 0.0210 seconds

https://issues.apache.org/jira/browse/HBASE-11613

清空表格:

时间: 2024-08-08 02:21:53

hbase操作的相关文章

spark 对hbase 操作

本文将分两部分介绍,第一部分讲解使用 HBase 新版 API 进行 CRUD 基本操作:第二部分讲解如何将 Spark 内的 RDDs 写入 HBase 的表中,反之,HBase 中的表又是如何以 RDDs 形式加载进 Spark 内的. 环境配置 为了避免版本不一致带来不必要的麻烦,API 和 HBase环境都是 1.0.0 版本.HBase 为单机模式,分布式模式的使用方法类似,只需要修改HBaseConfiguration的配置即可. 开发环境中使用 SBT 加载依赖项 name :=

第9章 HBase操作

目录 9.1 集群环境搭建 1.上传解压HBase安装包 2.hbase-env.sh文件配置 3.hbase-site.xml文件配置 4.regionservers文件配置 5.拷贝hbase到其它节点. 6.启动与测试 9.2 HBase Shell命令操作 1.创建表 2.添加数据 3.扫描表 4.修改表 5.删除特定单元格 6.删除一整行数据 7.删除整张表 9.3 Java API操作 9.3.1 创建Java工程 9.3.2 创建表 9.3.3 添加数据 9.3.4 查询数据 9.

HBase操作注意事项

1.HBase如果加了列限定,如果该列不存在时返回的结果为empty. 看下面的代码:   Get get = new Get(Bytes.toBytes("100"));     get.addColumn(Bytes.toBytes("info"), Bytes.toBytes("name")); 这里加入了列限定,也就是只返回列族info下面的name字段.但是如果name字段根本不存在,返回的Result在调用 result.isEmpt

hbase操作的问题

写了一个java程序,需要向hbase中写入大量的数据,但是这个程序执行一半就报错, 问题是,此时已经写入了很多数据. 查看jps,发现hmaster进程崩溃了. 基于以上信息,发现是在程序中,链接hbase后没有释放链接.导致链接达到hbase上限. 添加close(),解决问题.

HBase 操作

运行HBase自带的MapReduceHADOOP_CLASSPATH=`${HBASE_HOME}/bin/hbase classpath` ${HADOOP_HOME}/bin/hadoop jar ${HBASE_HOME}/lib/hbase-server-VERSION.jar rowcounter usertable CellCounter: Count cells in HBase table completebulkload: Complete a bulk data load.

熟悉常用的HBase操作

1. 以下关系型数据库中的表和数据,要求将其转换为适合于HBase存储的表并插入数据: 学生表(Student)(不包括最后一列) 学号(S_No) 姓名(S_Name) 性别(S_Sex) 年龄(S_Age) 课程(course) 2015001 Zhangsan male 23   2015003 Mary female 22   2015003 Lisi male 24 数学(Math)85 create 'Student', ' S_No ','S_Name', 'S_Sex','S_A

熟悉常用的HBase操作,编写MapReduce作业

1. 以下关系型数据库中的表和数据,要求将其转换为适合于HBase存储的表并插入数据: 学生表(Student)(不包括最后一列) 学号(S_No) 姓名(S_Name) 性别(S_Sex) 年龄(S_Age) 课程(course) 2015001 Zhangsan male 23   2015003 Mary female 22   2015003 Lisi male 24 数学(Math)85 2. 用Hadoop提供的HBase Shell命令完成相同任务: 列出HBase所有的表的相关信

熟悉常用的HBASE 操作

1.查看所有表 package cn.edu.zucc.hbase; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.client.Admi

小记--------sqoop的简单从mysql导入到hbase操作

sqoop import -D sqoop.hbase.add.row.key=true                        //是否将rowkey相关字段列入列族中,默认为false :该参数必须在import之后 --connect jdbc:mysql://120.27.208.185/bigdatatest        //连接mysql数据库 --username och_test                                    //mysql用户名