1.聲明
當前內容主要用於本人學習和複習,當前內容爲HBase中的QuickStart中使用HBase Shell的操作
當前內容的主要來源:HBase官方的QuickStart
當前內容基於博文:HBase的安裝和啓動
2.使用HBase SHell實現操作
查看是否啓動成功(顯示HMaster就表示單機模式啓動成功)
1.連接本地的HBase
./bin/hbase shell
顯示結果中說明了,沒有啓動本地的Hadoop庫,使用了builtin-java的類
可以使用help查看shell命令幫助
可以使用exit退出shell
2.查看幫助
help
3.create命令
Use the create command to create a new table. You must specify the table name and the ColumnFamily name.
使用create命令去創建一個新表,你必須使用特殊的表名和列族名
create 'test','cf'
意思就是創建表test以及創建列族爲cf
4.list命令
List Information About your Table
列出你的表的信息
Use the list command to confirm your table exists
使用list命令去告訴你表是否存在
list 'test'
list 'te'
當使用list列出一個不存在的結果,那麼返回的結果rows就是0(可以通過list檢查當前的table是否存在)
Now use the describe command to see details, including configuration default
顯示使用describe命令去顯示詳情,包括默認的配置
describe 'test'
5.put命令
To put data into your table, use the put command.
使用put命令向當前table中添加數據
put 'test', 'row1', 'cf:a', 'value1'
put 'test', 'row2', 'cf:b', 'value2'
put 'test', 'row3', 'cf:c', 'value3'
put 數據表,行名,列族:後綴,值
Here, we insert three values, one at a time. The first insert is at row1, column cf:a, with a value of value1. Columns in HBase are comprised of a column family prefix, cf in this example, followed by a colon and then a column qualifier suffix, a in this case.
這裏,我們一次性插入了三個值。這提一個插入的在row1,列cf:a,使用值value1.HBase中的列由一個列系列前綴(在本例中爲cf)組成,後跟一個冒號,然後是一個列限定符後綴(在本例中爲a)。
也就是說,當前添加的列實際上就是前面創建的列族前綴
+冒號:
+後綴方式
6.scan命令
Scan the table for all data at once.
一次性掃描表中的所有數據,使用scan
scan 'test'
7.get命令
Get a single row of data.
獲取單行數據
get 'test','row1'
get 數據表,行
8.disable和enable命令
禁用表
If you want to delete a table or change its settings, as well as in some other situations, you need to disable the table first, using the disable command. You can re-enable it using the enable command
如果你想要刪除表或者改變它的設置,以及在其他情況下,你需要在第一時間禁用表,使用disable命令
。你還可以使用enable命令重新啓用表
disable 'test'
enable 'test'
9.刪除表
disable 'test'
drop 'test'
list 'test'
10.退出hbase的shell
To exit the HBase Shell and disconnect from your cluster, use the quit command. HBase is still running in the background.
退出HBase Shell和斷開你的集羣連接,使用quit命令,HBase任然在後臺運行
quit
11.停止HBase
./bin/stop-hbase.sh
3.總結
1.創建表的時候需要指定表名和列族名稱,使用逗號分隔
2.通過bin/start-hbase.sh啓動HBase和使用bin/stop-hbase.sh停止HBase
3.添加數據時需要使用put方法,並指定表名,行名,列族:列,值方式添加數據,注意列實際爲列族+冒號+列方式
4.刪除當前的數據表的之前需要先禁用當前的表
以上純屬個人見解,如有問題請聯本人!