天天看點

Sql Line操作使用Hbase應用場景操作步驟

應用場景

按照 完全分布式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