ClickHouse错误(版本21.6.6):代码:1000 DB::Exception:异常:与所有副本的连接失败
ClickHouse error (version 21.6.6): Code: 1000 DB::Exception: Exception: Connections to all replicas failed
我正在尝试将 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的docker图片:
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 接收。 DB::Exception:异常:与所有副本的连接失败:amazon_redshift@localhost:3306 作为用户 root。
有人知道为什么吗?
原因是使用 localhost:3306,其中 localhost 指向容器,而不是外部主机。
出于测试目的考虑使用 network-settings 作为 host 以访问主机网络:
docker run --network="host" ..
作为替代方法,可以使用 docker-compose 来托管 MySQL 和 ClickHouse(参见示例 )。
代替使用 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/)
我正在尝试将 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的docker图片:
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 接收。 DB::Exception:异常:与所有副本的连接失败:amazon_redshift@localhost:3306 作为用户 root。
有人知道为什么吗?
原因是使用 localhost:3306,其中 localhost 指向容器,而不是外部主机。
出于测试目的考虑使用 network-settings 作为 host 以访问主机网络:
docker run --network="host" ..
作为替代方法,可以使用 docker-compose 来托管 MySQL 和 ClickHouse(参见示例
代替使用 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/)