LoginSignup
1
0

More than 3 years have passed since last update.

ClickHouseにmysqlコマンドでアクセスする

Last updated at Posted at 2020-01-30

ClickHosue v20.1.2.4(2020-01-22)でmysqlコマンドがクライアントとして使用できるようになっていたので使ってみます。

準備

mysqlコマンドを使用するには、設定ファイルにポート設定(mysql_port)を入れてやる必要があります。ここでは公式に従い9004ポートを使用することにします。設定を反映させるにはサーバの再起動が必要になります。

config.xml
<yandex>
  :
  <http_port>8123</http_port>
  <tcp_port>9000</tcp_port>
  <mysql_port>9004</mysql_port> <!-- このへんに追加 -->
  :
</yandex>

必要なのはこれだけです。

実行

使ってみます。Dockerの起動時にポートフォワード設定は入れてください。

$ mysql -h 127.0.0.1 -P 9004 -u default

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 20.1.2.4-ClickHouse

Copyright (c) 2000, 2019, 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> SHOW databases;

+---------+
| name    |
+---------+
| default |
| system  |
+---------+
2 rows in set (0.01 sec)
Read 2 rows, 239.00 B in 0.001 sec., 1743 rows/sec., 203.49 KiB/sec.

接続できました。何が嬉しいかと言われると、クライアントのDocker立ち上げなくてもいいとかその程度ですが、人に勧めるときちょっと叩いてみてもらうのにちょうどいいのかなとか思ったり。。。あと、mysqlクライアントベースのアプリ(あるのかは知らない)でも使えるようになったのかな。

INSERT ~ FORMATとかClickHouse独自の構文には対応できていないようですが、まあ仕方ないかなと思います。SELECTはできるので、簡単に集計を試すのには使えると思います。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0