Hbase安裝參考https://rumenz.com/rumenbiji/...html
因爲咱們安裝的是 hbase-2.3.1-bin.tar.gz ,因此須要下載 phoenix5.0以上
下載列表:http://archive.apache.org/dis...java
下載連接:http://archive.apache.org/dis...sql
咱們下載phoenix-5.0.0-HBase-2.0-bin.tar.gzshell
>tar -xzvf phoenix-5.0.0-HBase-2.0-bin.tar.gz >cd apache-phoenix-5.0.0-HBase-2.0-bin/ >cp phoenix-5.0.0-HBase-2.0-server.jar ../hbase-2.3.1/lib/ //而後重啓hbase >cd ../hbase-2.3.1/bin >./stop-hbase.sh >./start-hbase.sh //經過phoenix訪問hbase >apache-phoenix-5.0.0-HBase-2.0-bin/bin/sqlline.py 127.0.0.1:2818
若是長時間卡住或者報錯,應該是hbase啓動失敗,致使phoenix連接不上Hbase
解決方案:查看hbase的日誌apache
cat hbase-2.3.1/logs/hbase-root-regionserver-xxx.log
常見錯誤maven
java.lang.NoClassDefFoundError: org/apache/htrace/Sampler
緣由:oop
官方下載的phoenix沒有HTrace(phoenix從4.1.0版本開始就加入了收集每一個請求的traces的功能,這可讓你看到每一個重要的步驟(例如查詢操做或者插入操做)。phoenix經過利用cloudera公司的HTrace庫。),須要單獨下載放到hbase-2.3.1/lib/下。
我下載了:htrace-core-3.1.0-incubating.jar
1.下載連接:https://repo1.maven.org/maven...
2.拷貝htrace-core-3.1.0-incubating.jar到hbase-2.3.1/lib/目錄
3.而後重啓HBase便可ui
1.進入spa
>bin/sqlline.py 127.0.0.1:2181
2.退出(結尾不加分號)日誌
>!quit //或者 >!exit
3.查看全部的表
>!table
4.查看錶結構和列出metadata信息
>!desc "test1" >!dbinfo
前面命令前帶!號的,後面都不須要加分號,下面全部的命令操做都須要加分號結尾。
4.建立表
// namespace命名空間,提早在Hbase中建立好 create table "namespace:test1"("id" integer primary key,"col1"."name" varchar(30),"col2"."age" integer);
Phoenix中primary key和Hbase中RowKey的關係:在建立Phoenix table時,必須指定一個primary key,可是這個主鍵咱們不必定要用到,咱們用Phoenix建立table時,讓Phoenix的主鍵自動的和Hbase的rowkey關聯起來,可使用以下的方法。
create table "namespace:test1"("pk" integer primary key,"col1"."name" varchar(30),"col2"."age" integer);
這樣Phoenix的主鍵
pk
就自動的和Hbase的rowkey對應起來了
create table test1(pk integer primary key,col1.name varchar(30),col2.age integer);
表名和列族名區分大小寫,加了雙引號就必須用小寫去查,不然查不到.列名不區分大小寫,顯示大寫,依然能夠用小寫查到。在建立table時,沒有指定列族(family),只指定了列名qualifier(name,age),那麼在使用Hbase shell插入數據時,要寫成
put 'test1','1000','0:name','入門小站'
,不然Hbase會報錯ERROR: Unknown column family! Valid column names: 0:*
5.刪除表
drop table "test1";
6.修改表結構,添加屬性
alter table. "test1" add sex varchar(10);
7.建立一條索引
create index "test1_index" on "test1"("col1"."name");
8.刪除索引
drop "test1_index" on "test1";
9.向表中插入一條數據(字符串值只能用單引號括起來,雙引號會出錯,數字類型不用括起來)
upsert into "test1" values(1,'入門小站',20);
10.刪除表中的數據(字符串值只能用單引號括起來,雙引號會出錯,數字類型不用括起來)
delete from "test1" where name='入門小站';
11.修改表中的數據(必需要帶上主鍵id,值只能用單引號括起來,雙引號會出錯,數字類型不用括起來)
upsert into "test1"(id,age) values(1,30);
12.查詢表中的數據(字符串值必須用單引號括起來,雙引號會報錯,數字類型不用括起來)
select * from "test1"; select * from "test1" where age=30; select age,count(age) from "test2" where age>1 group by age;