在 Linux 环境下使用 HBase 建表,通常有两种方式:HBase Shell 和 Java API(或 Python/Thrift)。下面以最常用、最直观的 HBase Shell 方式为主说明,并补充 Java 示例。
start-hbase.sh
hbase shell
create 'student', 'info'
studentinfocreate 'user', 'base', 'ext'
create 'user', {NAME => 'base', VERSIONS => 3, TTL => 86400}
create 'order', 'cf', SPLITS => ['10', '20', '30']
避免数据热点,提高写入性能。
list
describe 'student'
put 'student', 'row1', 'info:name', 'zhangsan'
get 'student', 'row1'
scan 'student'
Configuration conf = HBaseConfiguration.create();
Connection conn = ConnectionFactory.createConnection(conf);
Admin admin = conn.getAdmin();
TableName tableName = TableName.valueOf("student");
HTableDescriptor table = new HTableDescriptor(tableName);
HColumnDescriptor cf = new HColumnDescriptor("info");
table.addFamily(cf);
admin.createTable(table);
✅ 表已存在
Table already exists
解决:
disable 'student'
drop 'student'
✅ 无法连接 HBase
hbase-site.xml如果你有 具体场景(如时间序列、日志、用户画像、亿级数据),我可以帮你设计更合理的表结构和预分区方案。