目录
hbase和mysql数据的交互
windows系统可以识别linux
打开C:\Windows\System32\drivers\etc\hosts 设置权限为可编辑
在末尾添上hostname和ip地址如:192.168.56.100 xuxu
hadoop端口:9000,hive端口:10000,
java代码的交互
建立新表
idea:
public class MyHbase {
public static void main(String[] args) throws Exception{
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum","192.168.56.100");
conf.set("hbase.zookeeper.property.clientPort","2181");
// 0.98版之后默认版本就是60000
conf.set("hbase.master","192.168.56.100:60000");
Connection conn = ConnectionFactory.createConnection(conf);
// 创建一个表
// 获得一个建表删表的对象HbaseAdmin
Admin admin = conn.getAdmin();
// 制造一个表名
TableName mytesttab = TableName.valueOf("mytesttab");
// 查询下表是否存在
if (!admin.tableExists(mytesttab)) {
// 建立一个表结构
HTableDescriptor table = new HTableDescriptor(mytesttab);
// 建立表下的列簇,并存放到表结构中
HColumnDescriptor base = new HColumnDescriptor("base");
table.addFamily(base);
HColumnDescriptor myinfo = new HColumnDescriptor("myinfo");
table.addFamily(myinfo);
// 完成建表
admin.createTable(table);
}
}
}
结果如下:
describe 'mytesttab'
扫描已存在的表:
public class MyHbase {
public static void main(String[] args) throws Exception{
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum","192.168.56.100");
conf.set("hbase.zookeeper.property.clientPort","2181");
// 0.98版之后默认版本就是60000
conf.set("hbase.master","192.168.56.100:60000");
Connection conn = ConnectionFactory.createConnection(conf);
// 取得userinfos表对象
TableName us = TableName.valueOf("mydemo:userinfos");
Table table = conn.getTable(us);
Scan scan = new Scan();
ResultScanner resultScanner =