应用场景
按照 完全分布式Hadoop集群安装Phoenix博文,安装了phoenix后,可以通过普通的SQL方式,操作HBASE,使hbase分布式非关系型数据库,更加易于用户的使用。
操作步骤
1. 启动phoenix
# sqlline.py hadoop0,hadoop1,hadoop2:2181
> !tables #启动完毕后,输入该命令进行测试
[root@hadoop0 opt]# sqlline.py hadoop0,hadoop1,hadoop2:2181
Setting property: [incremental, false]
Setting property: [isolation, TRANSACTION_READ_COMMITTED]
issuing: !connect jdbc:phoenix:hadoop0,hadoop1,hadoop2:2181 none none org.apache.phoenix.jdbc.PhoenixDriver
Connecting to jdbc:phoenix:hadoop0,hadoop1,hadoop2:2181
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/phoenix4.10.0/phoenix-4.10.0-HBase-1.2-client.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hadoop2.6.0/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
17/11/29 13:37:24 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Connected to: Phoenix (version 4.10)
Driver: PhoenixEmbeddedDriver (version 4.10)
Autocommit status: true
Transaction isolation: TRANSACTION_READ_COMMITTED
Building list of tables and columns for tab-completion (set fastconnect to true to skip)...
92/92 (100%) Done
Done
sqlline version 1.2.0
0: jdbc:phoenix:hadoop0,hadoop1,hadoop2:2181> !tables
+------------+--------------+-------------+---------------+----------+------------+----------------------+
| TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_NAME | SELF_REFERENCING_COL |
+------------+--------------+-------------+---------------+----------+------------+----------------------+
| | SYSTEM | CATALOG | SYSTEM TABLE | | | |
| | SYSTEM | FUNCTION | SYSTEM TABLE | | | |
| | SYSTEM | SEQUENCE | SYSTEM TABLE | | | |
| | SYSTEM | STATS | SYSTEM TABLE | | | |
+------------+--------------+-------------+---------------+----------+------------+----------------------+
2. 创建表
> create table test(id integer not null primary key,name varchar);
0: jdbc:phoenix:hadoop0,hadoop1,hadoop2:2181> create table test(id integer not null primary key,name varchar);
No rows affected (1.338 seconds)
3. 插入数据
> upsert into test values(0,'xubin');
0: jdbc:phoenix:hadoop0,hadoop1,hadoop2:2181> upsert into test values(0,'xubin');
1 row affected (0.012 seconds)
4. 查询数据
> select * from test;
0: jdbc:phoenix:hadoop0,hadoop1,hadoop2:2181> select * from test;
+-----+--------+
| ID | NAME |
+-----+--------+
| 0 | xubin |
| 1 | hello |
+-----+--------+
2 rows selected (0.03 seconds)
5. 退出phoenix
> !q
0: jdbc:phoenix:hadoop0,hadoop1,hadoop2:2181> !q
Closing: org.apache.phoenix.jdbc.PhoenixConnection