HBase shell命令 :
1.进入Hbase shell命令 (顺序:zkserver.sh 、start-dfs.sh、start-hbase.sh)
$>hbase shell
2.建议参照“help”命令
查看数据表list -->show tables;
3.shell命令
create创建表指令:
hbase(main):021:0> create 'customer','baseinfo','address'
put插入数据:
hbase(main):021:0> put 'customer','row-1','baseinfo:name','zhangsan'
hbase(main):021:0> put 'customer','row-1','baseinfo:age',12
hbase(main):021:0> put 'customer','row-1','baseinfo:sex','男'
hbase(main):021:0> put 'customer','row-1','address:city','长春'
scan扫描表:
hbase(main):021:0> scan 'customer'
ROW COLUMN+CELL
row-1 column=address:city, timestamp=1533057164343, value=changchun
row-1 column=baseinfo:age, timestamp=1533057275350, value=23
row-1 column=baseinfo:name, timestamp=1533056802314, value=zhangsan
row-1 column=baseinfo:sex, timestamp=1533057120030, value=\xE7\x94\xB7\x0A
1 row(s) in 0.1030 seconds
说明:当前显示的为一条记录;
get获取一行数据指令:
hbase(main):021:0> get 'customer','row-1'
COLUMN CELL
address:city timestamp=1533057164343, value=changchun
baseinfo:age timestamp=1533057275350, value=23
baseinfo:name timestamp=1533056802314, value=zhangsan
baseinfo:sex timestamp=1533057120030, value=\xE7\x94\xB7\x0A
1 row(s) in 0.1500 seconds
get获取一行中某一个Cell数据指令:
hbase(main):021:0> get 'customer','row-1','columfamily:name'
append追加指令:
append 'customer','row-1','baseinfo:name','aa12322'
delete删除记录指令 记录,单元格::
hbase(main):072:0> delete 'customer','row-2','baseinfo:name'
删除一行记录:
hbase(main):037:0> deleteall 'customer','row-2'
describe描述指令检索结构:
hbase(main):084:0> desc 'customer'
Table customer is ENABLED
customer
COLUMN FAMILIES DESCRIPTION
{NAME => 'address', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
{NAME => 'baseinfo', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS=> 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
2 row(s) in 0.5850 seconds
VERSION(版本):默认version为1,只能存1个版本
下面给出的语法新增列家族时并给出版本:
hbase(main):086:0> alter 'customer',{NAME=>'dept',VERSIONS=>5}
hbase(main):084:0> desc 'customer'
默认查询最新时间戳,检索当前表的数据版本;只有加上版本参数才能查询全部的:
hbase(main):119:0> put 'customer','row-2','dept:name','zhangsan1'
hbase(main):119:0> put 'customer','row-2','dept:name','zhangsan2'
hbase(main):119:0> put 'customer','row-2','dept:name','zhangsan3'
通过scan '表名',{VERSIONS=>*}指令,按timestamp时间戳进行降序:
scan 'customer',{VERSIONS=>5}
执行delete删除命令时,如需按照ts(timestamp)时间戳进行删除操作时,之前版本一并删除掉;
ase(main):017:0> delete 'customer','row-2','dept:name',1562395748955
再次查询:
hbase(main):018:0> scan 'customer',{VERSIONS=>5}
删除列族:alter 'table name', 'delete' => ' column family '
hbase> alter 'customer','delete'=>'dept'
truncate 清除表:
truncate 'tablename'
先查看表:hbase(main):049:0> list 'testTable'
drop删除table指令:
hbase(main):084:0> disable 'ns1:tablename' //说明:禁用table
hbase(main):084:0> drop 'ns1:tablename' //说明:删除table
get_table指令:将table映射成相对应的变量值(table实例),通过table实例对表进行相关操作
hbase(main):117:0> t1 = get_table 'customer'
hbase(main):118:0> t1.scan
hbase(main):119:0> t1.put 'row-2','baseinfo:name','zhangsan'
hbase(main):120:0> t1.get 'row-2'
hbase(main):120:0> t1.get 'row-2','baseinfo:name'
namespace命名空间,相当于传统数据库的表空间:
help 'namespace'
list_namespace 列出命名空间
list_namespace_tables 'default' 列出默认命名空间下有哪些表
hbase(main):003:0> create_namespace 'ns1',{'author'=>'zhangsan','data'=>'2018-07-31'}
hbase(main):005:0> describe_namespace 'ns1'
DESCRIPTION