启动Hbase shell
./bin/hbase shell
执行list列出Hbase中所有表
list
hbase:001:0> list TABLE 0 row(s) Took 0.8902 seconds => []
Hbase使用表作为顶级结构来存储数据。创建一个有列族的表
列族
hbase:002:0> create 'mytable', 'cf' Created table mytable Took 0.7812 seconds => Hbase::Table - mytable hbase:003:0> list TABLE mytable 1 row(s) Took 0.0204 seconds => ["mytable"]
在mytable表的first行中的cf:message列对应的数据单元中插入字节数组hello HBase
mytable
first
cf:message
hello HBase
put 'mytable', 'first', 'cf:message' , 'hello HBase';
Hbase存储数字与字符串的方式相同
put 'mytable', 'second', 'cf:foo' , 0x0; put 'mytable', 'third', 'cf:bar' , 3.14159;
现在表里有三行和三个数据单元
hbase:007:0> get 'mytable', 'first'; COLUMN CELL cf:message timestamp=2023-11-05T13:10:47.463, value=hello HBase 1 row(s) Took 0.0973 seconds
得到了第一行数据,按列组织,输出值附带时间戳。Hbase可以存储每个数据单元的多个时间版本。除非特被指定,否则返回最新时间版本。
hbase:009:0> scan 'mytable'; ROW COLUMN+CELL first column=cf:message, timestamp=2023-11-05T13:10:47.463, value=hello HBase second column=cf:foo, timestamp=2023-11-05T13:12:00.323, value=0 third column=cf:bar, timestamp=2023-11-05T13:12:27.124, value=3.14159 3 row(s) Took 0.0289 seconds
返回表里的所有行,返回顺序按行名排序,称为行键。
行键