HBase数据结构与基本语法详解(3)

3)删除数据
 a )删除行中的某个列值
# 语法:delete <table>, <rowkey>,  <family:column> , <timestamp>,必须指定列名
# 例如:删除表t1,rowkey001中的f1:col1的数据
hbase(main)> delete 't1','rowkey001','f1:col1'

注:将删除改行f1:col1列所有版本的数据

b )删除行
# 语法:deleteall <table>, <rowkey>,  <family:column> , <timestamp>,可以不指定列名,删除整行数据
# 例如:删除表t1,rowk001的数据
hbase(main)> deleteall 't1','rowkey001'

c)删除表中的所有数据
# 语法: truncate <table>
# 其具体过程是:disable table -> drop table -> create table
# 例如:删除表t1的所有数据
hbase(main)> truncate 't1'

Region管理

1)移动region
# 语法:move 'encodeRegionName', 'ServerName'
# encodeRegionName指的regioName后面的编码,ServerName指的是master-status的Region Servers列表
# 示例
hbase(main)>move '4343995a58be8e5bbc739af1e91cd72d', 'db-41.xxx.xxx.org,60020,1390274516739'

2)开启/关闭region
# 语法:balance_switch true|false
hbase(main)> balance_switch

3)手动split
# 语法:split 'regionName', 'splitKey'

4)手动触发major compaction
#语法:
#Compact all regions in a table:
#hbase> major_compact 't1'
#Compact an entire region:
#hbase> major_compact 'r1'
#Compact a single column family within a region:
#hbase> major_compact 'r1', 'c1'
#Compact a single column family within a table:
#hbase> major_compact 't1', 'c1'

配置管理及节点重启

1)修改hdfs配置
 hdfs配置位置:/etc/hadoop/conf
# 同步hdfs配置
cat /home/hadoop/slaves|xargs -i -t scp /etc/hadoop/conf/hdfs-site.xml hadoop@{}:/etc/hadoop/conf/hdfs-site.xml
#关闭:
cat /home/hadoop/slaves|xargs -i -t ssh hadoop@{} "sudo /home/hadoop/cdh4/hadoop-2.0.0-cdh4.2.1/sbin/hadoop-daemon.sh --config /etc/hadoop/conf stop datanode"
#启动:
cat /home/hadoop/slaves|xargs -i -t ssh hadoop@{} "sudo /home/hadoop/cdh4/hadoop-2.0.0-cdh4.2.1/sbin/hadoop-daemon.sh --config /etc/hadoop/conf start datanode"

2)修改hbase配置
 hbase配置位置:/home/hadoop/hbase
# 同步hbase配置
cat /home/hadoop/hbase/conf/regionservers|xargs -i -t scp /home/hadoop/hbase/conf/hbase-site.xml hadoop@{}:/home/hadoop/hbase/conf/hbase-site.xml
 
# graceful重启
cd ~/hbase
bin/graceful_stop.sh --restart --reload --debug inspurXXX.xxx.xxx.org

hbase shell 脚本

编写一个文本文件hbasedemo.txt:
disable 'table1'
drop 'table1'
create 'table1', 'column_family1','column_family2' 
list 'table1' 
put 'table1', 'row_key1', 'column_family1:col1', 'value1' 
put 'table1', 'row_key2', 'column_family1:col2', 'value2' 
put 'table1', 'row_key3', 'column_family2:col3', 'value3' 
put 'table1', 'row_key4', 'column_family2:col4', 'value4' 
scan 'table1' 
scan 'table1',{LIMIT=>5}
get 'table1', 'row_key1' 
get 'table1','row_key1', 'column_family1:col1'
count 'table1'

disable 'table1' 
alter 'table1',NAME=>'column_family3'
alter 'table1','delete'=>'column_family3'
enable 'table1'
describe 'table1'
grant 'root','RW','table1'
user_permission 'table1'

delete 'table1','row_key1','column_family1:col1'
deleteall 'table1','row_key1'
truncate 'table1'

在HBase shell中运行这个脚本
hbase shell hbasedemo.txt

需要注意的是,如果编写的txt文件中没有exit这条命令的话,当脚本执行完成后,会停留在hbase shell的界面中,如果有exit命令的话,就会退出到系统shell中。

Linux公社的RSS地址https://www.linuxidc.com/rssFeed.aspx

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/75576ab6e927885c6edf2160780290b0.html