Clickhouse 的MySQL接口

clickhouse默认提供了MySQL的端口:

#vim /etc/clickhouse-server/config.xml
   8123
    9000
    9004
    
    

1.用MySQL 官方的客户端登陆:

[root@hadoop ~]# mysqld -V
/usr/sbin/mysqld  Ver 8.0.20 for Linux on x86_64 (MySQL Community Server - GPL)
[root@hadoop ~]# mysql -h192.168.8.110 -udefault -P9004
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 20.4.5.36-ClickHouse 67108864

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select  * from system.one;
+-------+
| dummy |
+-------+
|     0 |
+-------+
1 row in set (0.00 sec)
Read 1 rows, 1.00 B in 0.000 sec., 4271 rows/sec., 4.17 KiB/sec.

mysql> select  * from system.collations limit 3;
+------+-----------+
| name | language  |
+------+-----------+
| af   | Afrikaans |
| am   | Amharic   |
| ar   | Arabic    |
+------+-----------+
3 rows in set (0.00 sec)
Read 132 rows, 3.81 KiB in 0.000 sec., 346921 rows/sec., 9.77 MiB/sec.

-- 创建表:
mysql> show databases;
+--------------------------------+
| name                           |
+--------------------------------+
| _temporary_and_external_tables |
| datasets                       |
| default                        |
| system                         |
+--------------------------------+
4 rows in set (0.00 sec)
Read 4 rows, 455.00 B in 0.000 sec., 8314 rows/sec., 923.64 KiB/sec.

mysql> use datasets;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

mysql> create table t(id bigint,username string,amount decimal(10,2),createtime datetime)engine=Memory;
ERROR 50 (00000): Unknown data type family: string. Maybe you meant: ['String']
mysql> create table t(id bigint,username String,amount decimal(10,2),createtime datetime)engine=Memory; 
Query OK, 0 rows affected (0.00 sec)


可以看到主要的数据类型都支持,varchar的需要用String类型替换,string的首字母必须大写。


mysql> insert into t values(100,'wuhan',200.25,now());
Query OK, 1 row affected (0.00 sec)
Read 1 rows, 34.00 B in 0.001 sec., 1521 rows/sec., 50.52 KiB/sec.

mysql> select * from t;
+------+----------+--------+---------------------+
| id   | username | amount | createtime          |
+------+----------+--------+---------------------+
|  100 | wuhan    | 200.25 | 2020-07-07 18:20:03 |
+------+----------+--------+---------------------+
1 row in set (0.00 sec)
Read 1 rows, 34.00 B in 0.000 sec., 2572 rows/sec., 85.41 KiB/sec.

登陆到clickhouse查询:
Clickhouse> select * from datasets.t;

SELECT *
FROM datasets.t

┌──id─┬─username─┬─amount─┬──────────createtime─┐
│ 100 │ wuhan    │ 200.25 │ 2020-07-07 18:20:03 │
└─────┴──────────┴────────┴─────────────────────┘

1 rows in set. Elapsed: 0.004 sec. 
可以看到查询的是一样的。

 

参考:

https://github.com/sysown/proxysql/wiki/ClickHouse-Support

你可能感兴趣的:(Clickhouse)