常用HBaseshell命令有哪些
这篇文章将为大家详细讲解有关常用HBase shell命令有哪些,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
成都创新互联公司主营浚县网站建设的网络公司,主营网站建设方案,app软件开发,浚县h5小程序开发搭建,浚县网站营销推广欢迎浚县等地区企业咨询
一:HBase
1.使用hbase 命令之前先检查一下hbase是否运行正常,通过JPS查看进程
hadoop@master:/mysoftware/hbase-1.2.1/bin$ jps 4051 HQuorumPeer 3776 QuorumPeerMain 2818 NameNode 4149 HMaster 3140 SecondaryNameNode 2966 DataNode 4549 Jps 4304 HRegionServer 3365 ResourceManager
2.进入HBase shell 客户端
hadoop@master:/mysoftware/hbase-1.2.1$ bin/hbase shell
二:HBase 基本命令概览
HBase Shell的一些基本操作命令,列出了几个常用的HBase Shell命令,如下:
名称 | 命令表达式 |
创建表 | create '表名称', '列名称1','列名称2','列名称N' |
添加记录 | put '表名称', '行名称', '列名称:xxx', '值' |
查看记录 | get '表名称', '行名称' |
查看表中的记录总数 | count '表名称' |
删除记录 | delete '表名' ,'行名称' , '列名称' |
删除一张表 | 先要屏蔽该表,才能对该表进行删除,第一步 disable '表名称' 第二步 drop '表名称' |
查看所有记录 | scan "表名称" |
查看某个表某个列中所有数据 | scan "表名称" , ['列名称:'] |
更新记录 | 就是重写一遍进行覆盖 |
三:HBase基本命令小实用,以下步骤
四:.一般操作
1.查询服务器状态:status
hbase(main):002:0> status 1 active master, 0 backup masters, 1 servers, 0 dead, 3.0000 average load
2.查询Hbase版本:version
hbase(main):003:0> vesion NameError: undefined local variable or method `vesion' for #
五:DDL操作
1.创建一张表userinfo :create 'userinfo','name','age'
hbase(main):011:0> create 'userinfo','name','age' 0 row(s) in 1.3220 seconds => Hbase::Table - userinfo
2.列出所有表:list
hbase(main):013:0> list TABLE table1 userinfo 2 row(s) in 0.0230 seconds => ["table1", "userinfo"]
3.获得表的描述:describe
hbase(main):014:0> describe 'userinfo' Table userinfo is ENABLED userinfo COLUMN FAMILIES DESCRIPTION {NAME => 'age', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSI ON => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'f alse', BLOCKCACHE => 'true'} {NAME => 'name', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESS ION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => ' false', BLOCKCACHE => 'true'} 2 row(s) in 0.0430 seconds
4.查看表是否存在:exists
hbase(main):017:0> exists 'table2' Table table2 does not exist 0 row(s) in 0.0210 seconds
5.判断表是否为:‘enable’
hbase(main):018:0> is_enabled 'userinfo' true
6.判断表是否为:‘disable’
hbase(main):019:0> is_disabled 'userinfo' false
7.删除一个列族 disable alter enable
hbase(main):003:0> disable 'table1' 0 row(s) in 0.0230 seconds hbase(main):004:0> alter 'table1',{ NAME => 't2' , METHOD => 'delete'} Updating all regions with the new schema... 1/1 regions updated. Done. 0 row(s) in 2.2240 seconds hbase(main):005:0> enable 'table1' 0 row(s) in 1.2990 seconds
然后在查看该列是否删除,看通过获得表的描述查看,如下: 只剩下列 ‘t1‘。
hbase(main):006:0> describe 'table1' Table table1 is ENABLED table1 COLUMN FAMILIES DESCRIPTION {NAME => 't1', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSIO N => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'fa lse', BLOCKCACHE => 'true'} 1 row(s) in 0.0290 seconds
8.删除一个表:drop , 删除表前,需要先屏蔽该表。
hbase(main):007:0> disable 'table1' 0 row(s) in 2.2910 seconds hbase(main):008:0> drop 'table1' 0 row(s) in 1.3030 seconds
六:DML操作
1.往userinfo中插入几条记录: put ’表名‘,’行名‘,’列族名:xxx‘,'value'
hbase(main):016:0> put 'userinfo','row1','name:col1','Berg' 0 row(s) in 0.0870 seconds hbase(main):017:0> put 'userinfo','row1','age:col2','22' 0 row(s) in 0.0180 seconds hbase(main):018:0> put 'userinfo','row2','name:col1','hadoophbase' 0 row(s) in 0.0190 seconds hbase(main):019:0> put 'userinfo','row2','age:col2','20' 0 row(s) in 0.0180 seconds
2.全表扫描:scan
hbase(main):001:0> scan 'userinfo' ROW COLUMN+CELL row1 column=age:col2, timestamp=1463066528653, value=22 row1 column=name:col1, timestamp=1463066505217, value=Berg row2 column=age:col2, timestamp=1463066598770, value=20 row2 column=name:col1, timestamp=1463066577206, value=hadoophbase
3. 获得某一行的所有数据,也是获得某一行名的所有数据
hbase(main):003:0> get 'userinfo', 'row1' COLUMN CELL age:col2 timestamp=1463066528653, value=22 name:col1 timestamp=1463066505217, value=Berg
4.获得某行,某列族,某列的所有数据
hbase(main):004:0> get 'userinfo','row1','name:col1' COLUMN CELL name:col1 timestamp=1463066505217, value=Berg 1 row(s) in 0.0190 seconds
5.更新一条记录 : put( name:col1的值更改为: BergBergBerg )
hbase(main):009:0> put 'userinfo','row2','name:col1','BergBergBerg' 0 row(s) in 0.0720 seconds
获取更新后的值:
hbase(main):011:0> get 'userinfo','row2','name:col1' COLUMN CELL name:col1 timestamp=1463067259346, value=BergBergBerg 1 row(s) in 0.0280 seconds
6.查询表中有多少行:count
hbase(main):012:0> count 'userinfo' 2 row(s) in 0.0450 seconds => 2
7.删除 某行 某列族的值:delete
hbase(main):023:0> delete 'userinfo','row2','age:col2' 0 row(s) in 0.0140 seconds hbase(main):024:0> scan 'userinfo' ROW COLUMN+CELL row1 column=age:col2, timestamp=1463066528653, value=22 row1 column=name:col1, timestamp=1463066505217, value=Berg row2 column=name:col1, timestamp=1463067259346, value=BergBergBerg 2 row(s) in 0.0300 seconds
8.删除整行的值:deleteall
hbase(main):026:0> deleteall 'userinfo','row2' 0 row(s) in 0.0190 seconds hbase(main):027:0> scan 'userinfo' ROW COLUMN+CELL row1 column=age:col2, timestamp=1463066528653, value=22 row1 column=name:col1, timestamp=1463066505217, value=Berg 1 row(s) in 0.0320 seconds
9.给 row1 这行 age列,并使用counter实现递增 : incr (好吧,做这里的时候有点怪,原因无他,列族名没有取得好。。。。。)
hbase(main):024:0> incr 'userinfo','row1','age:id' COUNTER VALUE = 1 0 row(s) in 0.0170 seconds hbase(main):025:0> incr 'userinfo','row1','age:id' COUNTER VALUE = 2 0 row(s) in 0.0210 seconds hbase(main):026:0> incr 'userinfo','row1','age:id' COUNTER VALUE = 3 0 row(s) in 0.1270 seconds
获取当前counter的值:
hbase(main):027:0> get_ get_auths get_counter get_splits get_table hbase(main):027:0> get_counter 'userinfo','row1','age:id' COUNTER VALUE = 3
10.将整个表清空:truncate
hbase(main):028:0> truncate 'userinfo' Truncating 'userinfo' table (it may take a while): - Disabling table... - Truncating table... 0 row(s) in 4.3360 seconds hbase(main):029:0> scan 'userinfo' ROW COLUMN+CELL 0 row(s) in 0.3490 seconds
关于“常用HBase shell命令有哪些”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
网站题目:常用HBaseshell命令有哪些
网站路径:http://hbruida.cn/article/ppccco.html