hbase经常使用的shell命令样例

1、hbase shell    进入hbase

[[email protected] ~]$ hbase shell

HBase Shell; enter ‘help<RETURN>‘ for list of supported commands.

Type "exit<RETURN>" to leave the HBase Shell

Version 0.94.16, r1557241, Fri Jan 10 20:10:24 UTC 2014

2、whoami    查看当前訪问hbase的用户

hbase(main):001:0> whoami

hadoop

3、version    查看当前hbase的版本号信息

hbase(main):002:0> version

0.94.16, r1557241, Fri Jan 10 20:10:24 UTC 2014

4、status    查看当前hbase的状态

hbase(main):003:0> status

2 servers, 0 dead, 1.0000 average load

也能够通过添加參数查看,status ‘simple‘ 查看简单的信息、status ‘summary‘ 查看概要信息、status ‘detailed‘ 查看具体信息

5、create    创建表

hbase(main):007:0> create ‘member‘,‘member_id‘,‘address‘,‘info‘

0 row(s) in 1.1590 seconds

6、list    查看数据库中的表

hbase(main):008:0> list

TABLE

member

1 row(s) in 0.0280 seconds

7、describe 表名    查看表的信息

hbase(main):009:0>describe member

NameError: undefined local variable or method `member‘ for #<Object:0x453c47>

hbase(main):010:0> describe ‘member‘

DESCRIPTION                                                                                                                  ENABLED

‘member‘, {NAME => ‘address‘, DATA_BLOCK_ENCODING => ‘NONE‘, BLOOMF    true

ILTER => ‘NONE‘, REPLICATION_SCOPE => ‘0‘, VERSIONS => ‘3‘, COMPRES

SION => ‘NONE‘, MIN_VERSIONS => ‘0‘, TTL => ‘2147483647‘, KEEP_DELE

TED_CELLS => ‘false‘, BLOCKSIZE => ‘65536‘, IN_MEMORY => ‘false‘, E

NCODE_ON_DISK => ‘true‘, BLOCKCACHE => ‘true‘}, {NAME => ‘info‘, DA

TA_BLOCK_ENCODING => ‘NONE‘, BLOOMFILTER => ‘NONE‘, REPLICATION_SCO

PE => ‘0‘, VERSIONS => ‘3‘, COMPRESSION => ‘NONE‘, MIN_VERSIONS =>

‘0‘, TTL => ‘2147483647‘, KEEP_DELETED_CELLS => ‘false‘, BLOCKSIZE

=> ‘65536‘, IN_MEMORY => ‘false‘, ENCODE_ON_DISK => ‘true‘, BLOCKCA

CHE => ‘true‘}, {NAME => ‘member_id‘, DATA_BLOCK_ENCODING => ‘NONE‘

, BLOOMFILTER => ‘NONE‘, REPLICATION_SCOPE => ‘0‘, VERSIONS => ‘3‘,

COMPRESSION => ‘NONE‘, MIN_VERSIONS => ‘0‘, TTL => ‘2147483647‘, K

EEP_DELETED_CELLS => ‘false‘, BLOCKSIZE => ‘65536‘, IN_MEMORY => ‘f

alse‘, ENCODE_ON_DISK => ‘true‘, BLOCKCACHE => ‘true‘}

1 row(s) in 0.0450 seconds

hbase(main):011:0>

8、删除列族

删除列族须要先禁用表,否则会报下面错误:

hbase(main):006:0> alter ‘member‘,NAME=>‘member_id‘,METHOD=>‘delete‘

ERROR: org.apache.hadoop.hbase.TableNotDisabledException: org.apache.hadoop.hbase.TableNotDisabledException: member

at org.apache.hadoop.hbase.master.HMaster.checkTableModifiable(HMaster.java:1525)

at org.apache.hadoop.hbase.master.handler.TableEventHandler.<init>(TableEventHandler.java:72)

at org.apache.hadoop.hbase.master.handler.TableDeleteFamilyHandler.<init>(TableDeleteFamilyHandler.java:41)

at org.apache.hadoop.hbase.master.HMaster.deleteColumn(HMaster.java:1430)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.apache.hadoop.hbase.ipc.WritableRpcEngine$Server.call(WritableRpcEngine.java:323)

at org.apache.hadoop.hbase.ipc.HBaseServer$Handler.run(HBaseServer.java:1426)

删除列族的正确方法:

先禁用表:

hbase(main):007:0> disable ‘member‘

0 row(s) in 1.1690 seconds

然后删除列族(注意NAME和METHOD要大写):

hbase(main):008:0> alter ‘member‘,NAME=>‘member_id‘,METHOD=>‘delete‘

Updating all regions with the new schema...

1/1 regions updated.

Done.

0 row(s) in 1.1640 seconds

删除列族之后再启用表:

hbase(main):009:0> enable ‘member‘

0 row(s) in 1.2250 seconds

再次查看表信息,便能够发现member_id已经被删除

hbase(main):010:0>describe ‘member‘

DESCRIPTION                                                                                                                                                                                      
     ENABLED

‘member‘, {NAME => ‘address‘, DATA_BLOCK_ENCODING => ‘NONE‘, BLOOMFILTER => ‘NONE‘, REPLICATION_SCOPE => ‘     true

0‘, VERSIONS => ‘3‘, COMPRESSION => ‘NONE‘, MIN_VERSIONS => ‘0‘, TTL => ‘2147483647‘, KEEP_DELETED_CELLS =

> ‘false‘, BLOCKSIZE => ‘65536‘, IN_MEMORY => ‘false‘, ENCODE_ON_DISK => ‘true‘, BLOCKCACHE => ‘true‘}, {N

AME => ‘info‘, DATA_BLOCK_ENCODING => ‘NONE‘, BLOOMFILTER => ‘NONE‘, REPLICATION_SCOPE => ‘0‘, VERSIONS =>

‘3‘, COMPRESSION => ‘NONE‘, MIN_VERSIONS => ‘0‘, TTL => ‘2147483647‘, KEEP_DELETED_CELLS => ‘false‘, BLOC

KSIZE => ‘65536‘, IN_MEMORY => ‘false‘, ENCODE_ON_DISK => ‘true‘, BLOCKCACHE => ‘true‘}

1 row(s) in 0.0420 seconds

9、drop 表名    删除表

删除表时也须要先将表disable,否则会报错。为方便先创建个暂时表(user表)。然后将user表删除

hbase(main):019:0> create ‘user‘,‘name‘,‘age‘

0 row(s) in 1.0900 seconds

没有禁用user表,直接删除,报下面错误:

hbase(main):020:0> drop ‘user‘

ERROR: Table user is enabled. Disable it first.‘

Here is some help for this command:

Drop the named table. Table must first be disabled: e.g. "hbase> drop ‘t1‘"

正确删除方法例如以下:

先禁用表:

hbase(main):021:0> disable ‘user‘

0 row(s) in 1.1660 seconds

然后删除表:

hbase(main):022:0> drop ‘user‘

0 row(s) in 1.0710 seconds

hbase(main):023:0>

10、exists 表名    查看一个表是否存在

hbase(main):023:0> exists ‘user‘

Table user does not exist

0 row(s) in 0.0230 seconds

hbase(main):024:0> exists ‘member‘

Table member does exist

0 row(s) in 0.0750 seconds

11、is_enabled    推断表是否enable

hbase(main):025:0> is_enabled ‘member‘

true

0 row(s) in 0.0160 seconds

12、is_disabled    推断表是否disable

hbase(main):026:0> is_disabled ‘member‘

false

0 row(s) in 0.0220 seconds

13、put    插入数据

hbase(main):076:0> put ‘member‘,‘xueba‘,‘info:age‘,‘25‘

0 row(s) in 0.0170 seconds

为了方便使用以下命令的,这里多插入一些数据:

put ‘member‘,‘xueba‘,‘info:age‘,‘25‘

put ‘member‘,‘xueba‘,‘info:birthday‘,‘1989-06-19‘

put ‘member‘,‘xueba‘,‘info:company‘,‘tecent‘

put ‘member‘,‘xueba‘,‘address:contry‘,‘china‘

put ‘member‘,‘xueba‘,‘address:province‘,‘guangdong‘

put ‘member‘,‘xueba‘,‘address:city‘,‘shenzhen‘

put ‘member‘,‘xiaoming‘,‘info:age‘,‘24‘

put ‘member‘,‘xiaoming‘,‘info:birthday‘,‘1990-03-22‘

put ‘member‘,‘xiaoming‘,‘info:company‘,‘tecent‘

put ‘member‘,‘xiaoming‘,‘info:favorite‘,‘movie‘

put ‘member‘,‘xiaoming‘,‘address:contry‘,‘china‘

put ‘member‘,‘xiaoming‘,‘address:province‘,‘guangdong‘

put ‘member‘,‘xiaoming‘,‘address:city‘,‘guangzhou‘

14、get    获取表数据

获取xueba的信息:

hbase(main):090:0> get ‘member‘,‘xueba‘

COLUMN                      CELL

address:city               timestamp=1436932081705, value=shenzhen

address:contry             timestamp=1436932081662, value=china

address:province           timestamp=1436932081686, value=guangdong

info:age                   timestamp=1436932081590, value=25

info:birthday              timestamp=1436932081619, value=1989-06-19

info:company               timestamp=1436932081642, value=tecent

6 row(s) in 0.0080 seconds

获取xiaoming的info信息:

hbase(main):091:0> get ‘member‘,‘xiaoming‘,‘info‘

COLUMN                      CELL

info:age                   timestamp=1436932081724, value=24

info:birthday              timestamp=1436932081745, value=1990-03-22

info:company               timestamp=1436932081764, value=tecent

info:favorite              timestamp=1436932081784, value=movie

4 row(s) in 0.0560 seconds

获取xiaoming的age信息

hbase(main):092:0> get ‘member‘,‘xiaoming‘,‘info:age‘

COLUMN                      CELL

info:age                   timestamp=1436932081724, value=24

1 row(s) in 0.0060 seconds

15、put    更新记录

将xueba的age改为26:

hbase(main):093:0> put ‘member‘,‘xueba‘,‘info:age‘,‘26‘

0 row(s) in 0.0120 seconds

查看改动结果:

hbase(main):094:0> get ‘member‘,‘xueba‘,‘info:age‘

COLUMN                      CELL

info:age                   timestamp=1436932900139, value=26

1 row(s) in 0.0070 seconds

16、通过timestamp获取数据

hbase(main):099:0> get ‘member‘,‘xueba‘,{COLUMN=>‘info:age‘,TIMESTAMP=>1436936294957}

COLUMN                      CELL

info:age                   timestamp=1436936294957, value=26

1 row(s) in 0.0100 seconds

17、scan 表名    全表扫描

hbase(main):101:0> scan ‘member‘

ROW                         COLUMN+CELL

xiaoming                   column=address:city, timestamp=1436932131672, value=guangzhou

xiaoming                   column=address:contry, timestamp=1436932081802, value=china

xiaoming                   column=address:province, timestamp=1436932081821, value=guangdong

xiaoming                   column=info:age, timestamp=1436932081724, value=24

xiaoming                   column=info:birthday, timestamp=1436932081745, value=1990-03-22

xiaoming                   column=info:company, timestamp=1436932081764, value=tecent

xiaoming                   column=info:favorite, timestamp=1436932081784, value=movie

xueba                      column=address:city, timestamp=1436932081705, value=shenzhen

xueba                      column=address:contry, timestamp=1436932081662, value=china

xueba                      column=address:province, timestamp=1436932081686, value=guangdong

xueba                      column=info:age, timestamp=1436936294957, value=26

xueba                      column=info:birthday, timestamp=1436932081619, value=1989-06-19

xueba                      column=info:company, timestamp=1436932081642, value=tecent

2 row(s) in 0.0270 seconds

这里数据是2行,各自是xiaoming、xueba

18、delete    删除数据

删除xueba的age数据

hbase(main):102:0> delete ‘member‘,‘xueba‘,‘info:age‘

0 row(s) in 0.0400 seconds

删除后查看xueba信息,已没有age数据

hbase(main):103:0> get ‘member‘,‘xueba‘

COLUMN                      CELL

address:city               timestamp=1436932081705, value=shenzhen

address:contry             timestamp=1436932081662, value=china

address:province           timestamp=1436932081686, value=guangdong

info:birthday              timestamp=1436932081619, value=1989-06-19

info:company               timestamp=1436932081642, value=tecent

5 row(s) in 0.0160 seconds

19、deleteall    删除整行

删除xiaoming的数据:

hbase(main):104:0> deleteall ‘member‘,‘xiaoming‘

0 row(s) in 0.0100 seconds

查看删除情况。能够看出已没有xiaoming的数据

hbase(main):105:0> get ‘member‘,‘xiaoming‘

COLUMN                      CELL

0 row(s) in 0.0050 seconds

20、count 表名    查询表中总共同拥有多少行数据

hbase(main):106:0>count ‘member‘

1 row(s) in 0.0200 seconds

总共插入两行数据。上面将xiaoming的数据所有删除了。所以仅仅剩一行xueba的数据

21、truncate 表名    清空表

hbase(main):107:0> truncate ‘member‘

Truncating ‘member‘ table (it may take a while):

- Disabling table...

- Dropping table...

- Creating table...

0 row(s) in 3.2460 seconds

通过上面信息能够看出。清空表的操作是先禁用表,然后删除表,再又一次创建表

时间: 2024-10-07 19:48:45

hbase经常使用的shell命令样例的相关文章

Hbase的一些简单shell命令

进入hbase shell console$HBASE_HOME/bin/hbase shell如果有kerberos认证,需要事先使用相应的keytab进行一下认证(使用kinit命令),认证成功之后再使用hbase shell进入可以使用whoami命令可查看当前用户 hbase(main)> whoami 表的管理1)查看有哪些表 hbase(main)> list 2)创建表 # 语法:create <table>, {NAME => <family>,

HBase介绍(4)---常用shell命令

进入hbase shell console$HBASE_HOME/bin/hbase shell如果有kerberos认证,需要事先使用相应的keytab进行一下认证(使用kinit命令),认证成功之后再使用hbase shell进入可以使用whoami命令可查看当前用户 hbase(main)> whoami 表的管理1)查看有哪些表 hbase(main)> list 2)创建表 # 语法:create <table>, {NAME => <family>,

15个基本的ls命令样例(linux)

1. ls裸命令仅显示文件和目录 # ls 0001.pcap        Desktop    Downloads         index.html   install.log.syslog  Pictures  Templates anaconda-ks.cfg  Documents  fbcmd_update.php  install.log  Music               Public    Videos 2 .Ls的-l选项显示:权限.拥有着.大小.修改日期.文件/目录

CURL常用命令---样例

原文地址: http://www.thegeekstuff.com/2012/04/curl-examples/ 下载单个文件,默认将输出打印到标准输出中(STDOUT)中 curl http://www.centos.org 通过-o/-O选项保存下载的文件到指定的文件中:-o:将文件保存为命令行中指定的文件名的文件中-O:使用URL中默认的文件名保存文件到本地 1 # 将文件下载到本地并命名为mygettext.html 2 curl -o mygettext.html http://www

java操作hbase样例

hbase安装方法请參考:hbase-0.94安装方法具体解释 hbase经常使用的shell命令请參考:hbase经常使用的shell命令样例 java操作hbase,在eclipse中创建一个java项目.将hbase安装文件根文件夹的jar包和lib文件夹下jar包导入项目,然后就能够编写java代码操作hbase了. 以下代码给出来一个简单的演示样例 /** * @date 2015-07-23 21:28:10 * @author sgl */ package com.songguol

HBase Filter程序样例及Shell(图)

==过滤器执行流程== reset() : reset the filter state before filtering a new row. filterAllRemaining(): true means row scan is over; false means keep going. filterRowKey(byte[],int,int): true means drop this row; false means include. filterKeyValue(Cell): dec

Linux crontab 命令格式与具体样例

基本格式 : * * * * * command 分 时 日 月 周 命令 第1列表示分钟1-59 每分钟用*或者 */1表示 第2列表示小时1-23(0表示0点) 第3列表示日期1-31 第4列表示月份1-12 第5列标识号星期0-6(0表示星期天) 第6列要执行的命令 crontab文件的一些样例: 30 21 * * * /usr/local/etc/rc.d/lighttpd restart 上面的样例表示每晚的21:30重新启动apache. 45 4 1,10,22 * * /usr

linux命令单次或组合样例

[[email protected] ~]# which passwd/usr/bin/passwd[[email protected] ~]# whereis passwdpasswd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz[[email protected] ~]# locate passwd/etc/passwd/etc/passwd-/etc/

shell 学习一 概况及样例

shell: 1)是linux操作系统上使用的一种脚本语言,为用户与系统交互提供接口,与windows中命令提示符类似,但更为强大: 2)可以命令行执行,也可以编辑为脚本文件执行: 3)主要针对自动化简单系统或软件操作任务: 4)易于配置.维护和移植,不看中执行效率: 5)通用shell是GNU工具集中的bash(GNU Bourne-Again Shell),默认安装在/bin/bash,可以使用命令查看bash版本号:/bin/bash --version 样例: 在linux系统下打开终端