我正在尝试将ClickHouse与本地MySQL数据库连接起来,即使用引擎MYSQL。我已经运行了这些命令来获取重要的数据。
mysql> SELECT * FROM amazon_redshift.analytics limit 10;
+-------+------------+----------+------------+------------+-----------------------------+-------------------------------+-------------------------+
| count | date | store_id | created_at | updated_at | ret_cust_rate | orders_ret_cust | recommendation_accuracy |
+-------+------------+----------+------------+------------+-----------------------------+-------------------------------+-------------------------+
| 875 | 2021-03-01 | 199703 | 2021-07-26 | 2021-07-26 | {"new":"1","returning":"0"} | {"new":"100","returning":"0"} | NULL |
| 425 | 2021-03-01 | 212743 | 2021-07-26 | 2021-07-26 | {"new":"1","returning":"0"} | {"new":"100","returning":"0"} | NULL |
| 81 | 2021-03-01 | 213745 | 2021-07-26 | 2021-07-26 | {"new":"1","returning":"0"} | {"new":"100","returning":"0"} | NULL |
| 189 | 2021-03-01 | 204112 | 2021-07-26 | 2021-07-26 | {"new":"1","returning":"0"} | {"new":"100","returning":"0"} | NULL |
| 309 | 2021-03-01 | 204125 | 2021-07-26 | 2021-07-26 | {"new":"1","returning":"0"} | {"new":"100","returning":"0"} | NULL |
| 761 | 2021-03-01 | 209940 | 2021-07-26 | 2021-07-26 | {"new":"1","returning":"0"} | {"new":"100","returning":"0"} | NULL |
| 699 | 2021-03-01 | 214119 | 2021-07-26 | 2021-07-26 | {"new":"1","returning":"0"} | {"new":"100","returning":"0"} | NULL |
| 913 | 2021-03-01 | 201062 | 2021-07-26 | 2021-07-26 | {"new":"1","returning":"0"} | {"new":"100","returning":"0"} | NULL |
| 792 | 2021-03-01 | 210493 | 2021-07-26 | 2021-07-26 | {"new":"1","returning":"0"} | {"new":"100","returning":"0"} | NULL |
| 182 | 2021-03-01 | 203925 | 2021-07-26 | 2021-07-26 | {"new":"1","returning":"0"} | {"new":"100","returning":"0"} | NULL |
+-------+------------+----------+------------+------------+-----------------------------+-------------------------------+-------------------------+
10 rows in set (0,00 sec)
mysql> status
--------------
mysql Ver 8.0.25-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
Connection id: 13
Current database: amazon_redshift
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 8.0.25-0ubuntu0.20.04.1 (Ubuntu)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/run/mysqld/mysqld.sock
Binary data as: Hexadecimal
Uptime: 2 hours 53 min 46 sec
Threads: 2 Questions: 52 Slow queries: 0 Opens: 157 Flush tables: 3 Open tables: 76 Queries per second avg: 0.004
--------------
mysql> SELECT SUBSTRING_INDEX(USER(), '@', -1) AS ip, @@hostname as hostname, @@port as port, DATABASE() as current_database;
+-----------+--------------------------------+------+------------------+
| ip | hostname | port | current_database |
+-----------+--------------------------------+------+------------------+
| localhost | helena-ZenBook-UX451FL-UX289FL | 3306 | amazon_redshift |
+-----------+--------------------------------+------+------------------+
$ sudo lsof -i TCP:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 1134 mysql 27u IPv4 42528 0t0 TCP localhost:mysql (LISTEN)
然后我运行了clickHouse的码头映像:
CREATE DATABASE dummy ENGINE = Memory;
CREATE TABLE dummy.analytics
(
`count` UInt8,
`date` date NOT NULL,
`store_id` bigint NOT NULL,
`created_at` date NOT NULL,
`updated_at` date NOT NULL,
`ret_cust_rate` text,
`orders_ret_cust` text,
`recommendation_accuracy` text
)
ENGINE = MySQL('localhost:3306', 'amazon_redshift', 'analytics', 'root', 'Password9876')
SELECT *
FROM dummy.analytics
LIMIT 10;
从服务器接收异常(21.6.6版本):代码: 1000。DB::Exception:从clickhouse-server:9000收到。异常:异常:连接到所有副本的失败: amazon_redshift@localhost:3306作为用户根。
有人知道为什么吗?
发布于 2021-07-26 17:33:55
原因是使用localhost:3306,其中localhost指向容器,而不是外部主机。
出于测试目的,考虑使用网络-settings作为主机访问主机网络:
docker run --network="host" ..
作为另一种方式,可以使用docker同时托管MySQL和ClickHouse (例如,请参见CH & Kafka)。
发布于 2021-07-27 10:21:21
使用docker时,我以其他方式启动了clickHouse客户机:
sudo apt-get install apt-transport-https ca-certificates dirmngr
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E0C56BD4
echo "deb https://repo.clickhouse.tech/deb/stable/ main/" | sudo tee \
/etc/apt/sources.list.d/clickhouse.list
sudo apt-get update
sudo apt-get install -y clickhouse-server clickhouse-client
sudo service clickhouse-server start
clickhouse-client --password=<your-password>
然后使用另一个命令:
CREATE DATABASE analytics ENGINE = MySQL('127.0.0.1:3306', 'amazon_redshift', 'root', 'Password9876')
并且它的工作原理与ClickHouse示例(https://clickhouse.tech/docs/en/engines/database-engines/mysql/)一样正确。
发布于 2022-08-18 10:42:34
您的mysql需要访问者ip白名单
https://stackoverflow.com/questions/68533770
复制相似问题