mkdir -p /opt/soft
cd /opt/soft
wget https://dlcdn.apache.org/phoenix/phoenix-5.1.3/phoenix-hbase-2.5-5.1.3-bin.tar.gz
tar -zxvf phoenix-hbase-2.5-5.1.3-bin.tar.gz
mv phoenix-hbase-2.5-5.1.3-bin phoenix
vim /etc/profile
export PHOENIX_HOME=/opt/soft/phoenix
export PATH=$PATH:$PHOENIX_HOME/bin
source /etc/profile
scp /opt/soft/phoenix/phoenix-server-hbase-2.5-5.1.3.jar root@spark01:/opt/soft/hbase2/lib
scp /opt/soft/phoenix/phoenix-server-hbase-2.5-5.1.3.jar root@spark02:/opt/soft/hbase2/lib
scp /opt/soft/phoenix/phoenix-server-hbase-2.5-5.1.3.jar root@spark03:/opt/soft/hbase2/lib
stop-hbase.sh
start-hbase.sh
sqlline.py spark01,spark02,spark03
注意:会出现如下报错信息
/usr/bin/env: ‘python’: No such file or directory
whereis python3
# 这里是 whereis python3 的 提示信息
python3: /usr/bin/python3
ln /usr/bin/python3 /usr/bin/python
# 再次连接
sqlline.py spark01,spark02,spark03
使用 !table 或者 !tables
phoenix中没有database,有的是schema,相当于mysql中的数据库
create schema lihaozhe
会出现以下错误:
原因是需要在hbase的conf目录中的hbase-site.xml配置一个参数:
此参数是phoenix的schema和hbase的nameSpace命名空间做映射。
phoenix.schema.isNamespaceMappingEnabled将它设置成true
<property>
<name>phoenix.schema.isNamespaceMappingEnabledname>
<value>truevalue>
property>
<property>
<name>phoenix.schema.mapSystemTablesToNamespacename>
<value>truevalue>
property>
再次创建schema:
注意:schema “lihaozhe” 加双引号映射到hbase会是小写的,不加双引号默认都是大写的
create schema "lihaozhe";
https://phoenix.apache.org/columnencoding.html
unsigned_long
create table "tb_user"(
"user_id" varchar primary key,
"name" varchar,
"gender" varchar,
"home_address" varchar,
"company_address" varchar
);
create table "tb_emp"(
"emp_id" varchar primary key,
"info"."name" varchar,
"info"."gender" varchar,
"logistics"."home_address" varchar,
"logistics"."company_address" varchar
) COLUMN_ENCODED_BYTES = 0;
upsert into "tb_user" values ('1001','lhz','1','jilin','shanxi');
upsert into "tb_emp" values ('1001','lhz','1','jilin','shanxi');
show tables;
drop table "tb_user";
在 hbase 上创建表并插入数据
create 'lihaozhe:person', 'info', 'msg'
put 'lihaozhe:person','1001','info:name','user1001'
put 'lihaozhe:person','1001','info:gender','1'
put 'lihaozhe:person','1001','msg:slogan','hello world'
put 'lihaozhe:person','1002','info:name','user1002'
put 'lihaozhe:person','1002','info:gender','0'
put 'lihaozhe:person','1002','msg:slogan','hello'
put 'lihaozhe:person','1003','info:name','user1003'
put 'lihaozhe:person','1003','info:gender','1'
put 'lihaozhe:person','1003','msg:slogan','hi'
create view "person"(
"person_id" varchar primary key,
"info"."name" varchar,
"info"."gender" varchar,
"msg"."slogan" varchar
) column_encoded_bytes=0;
select * from "person";
drop view "person";
- 当 HBase 中已经存在表时,可以以类似创建视图的方式创建关联表,只需要将create view 改为 create table 即可。
- 当 HBase 中不存在表时,可以直接使用 create table 指令创建需要的表,系统将会自动在 Phoenix 和 HBase 中创建 person_infomation 的表,并会根据指令内的参数对表结构进行初始化。
create table "person"(
"person_id" varchar primary key,
"info"."name" varchar,
"info"."gender" varchar,
"msg"."slogan" varchar
) column_encoded_bytes=0;
select * from "person";
upsert into "person" values('1004','user1004','0','hw');
upsert into "person" ("person_id","gender") values('1001','0');
drop table "person";
!quit