0%

背景

Grafana从apache druid数据源获取数据。找到以下官方插件,但是很久不更新了。

官方插件开发:https://github.com/grafana-druid-plugin/druidplugin

维护者相关讨论:https://github.com/grafana-druid-plugin/druidplugin/issues/91

其中一个贡献者另外维护的的forked version

forked version:https://github.com/GoshPosh/druidplugin

Read more »

Introduction

Grafana - UI of analytics and monitoring
The open platform for beautiful analytics and monitoring
No matter where your data is, or what kind of database it lives in, you can bring it together with Grafana. Beautifully.

Read more »

Install

Installation python

1
2
3
4
5
6
7
8
9
10
11
# install
yum install python36

# 如果有旧版本,例如python2,修改默认python
cd /usr/bin
rm -rf python
rm -rf python2 # 是否需要?
ln -s python3.4 python

# check
python -V

Q&A

  • 解决系统python软链接指向python2.7版本后,yum不能正常工作

修改/usr/bin/yum,将文件头部的

1
#!/usr/bin/python

改成

1
#!/usr/bin/python2.4.3

关键字

distinct

1
2
3
4
5
6
SELECT DISTINCT(gender) FROM employees;

gender
--------
M
F

但是以下情况失效。这时适合用group by

1
2
SELECT DISTINCT(gender), emp_no FROM employees;
SELECT gender, emp_no FROM employees GROUP BY gender;

创建官方测试库

官方 Employees Sample Database
Git: https://github.com/datacharmer/test_db

  1. MySQL 5.5+

  2. Download the repository

  3. Change directory to the repository
    Then run

    1
    mysql < employees.sql

基本操作

See https://www.runoob.com/mysql/mysql-index.html

修改表结构(添加索引)

1
2
3
4
ALTER TABLE tbl_name ADD PRIMARY KEY (column_list); -- 该语句添加一个主键,这意味着索引值必须是唯一的,且不能为NULL。
ALTER TABLE tbl_name ADD UNIQUE index_name (column_list); -- 这条语句创建索引的值必须是唯一的(除了NULL外,NULL可能会出现多次)。
ALTER TABLE tbl_name ADD INDEX index_name (column_list); -- 添加普通索引,索引值可出现多次。
ALTER TABLE tbl_name ADD FULLTEXT index_name (column_list); -- 该语句指定了索引为 FULLTEXT ,用于全文索引。

创建表的时候直接指定

1
2
3
4
5
6
7
CREATE TABLE mytable(  
ID INT NOT NULL,
username1 VARCHAR(16) NOT NULL,
username2 VARCHAR(16) NOT NULL,
INDEX [indexName] (username1(length)) ,
UNIQUE [indexName] (username2(length))
);

删除索引的语法

1
2
DROP INDEX [indexName] ON mytable; 
ALTER TABLE tbl_name DROP INDEX index_name;

查看索引

1
SHOW INDEX FROM table_name;

查看索引大小

1
2
3
USE `information_schema`;

SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024), 2), ' MB') AS 'Total Index Size' FROM `TABLES` WHERE table_name = 'dept_emp';

Index Type

const

1
2
3
4
5
6
EXPLAIN SELECT * FROM employees.titles WHERE emp_no='10001' AND title='Senior Engineer' AND from_date='1986-06-26';
+----+-------------+--------+-------+---------------+---------+---------+-------------------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+-------+---------------+---------+---------+-------------------+------+-------+
| 1 | SIMPLE | titles | const | PRIMARY | PRIMARY | 59 | const,const,const | 1 | |
+----+-------------+--------+-------+---------------+---------+---------+-------------------+------+-------+

理论上索引对顺序是敏感的,但是由于MySQL的查询优化器会自动调整where子句的条件顺序以使用适合的索引