|
|
@ -85,9 +85,12 @@ ClickHouse也内置了许多机器学习算法,例如基于梯度下降的线 |
|
|
|
### 二)登录数据仓库。Clickhouse数据仓库的登录有很多方式,比如用clickhouse客户端登录,用JDBC(在Java中使用)或者ODBC(在C/C++中使用)访问,用clickhouse-driver(在Python中使用)访问。本实验我们完成clickhouse客户端和clickhouse-driver两种方式。其余方式同学们以后可以自行尝试。 |
|
|
|
|
|
|
|
#### 1)使用Clickhouse客户端登录。创建一个最低配置的Centos云主机,选择按流量计费,20M带宽,云主机按小时付费。登录云主机以后运行以下命令,下载Clickhouse安装包。 |
|
|
|
|
|
|
|
因为网络原因,我们使用阿里云的镜像安装 |
|
|
|
|
|
|
|
``` |
|
|
|
wget https://packages.clickhouse.com/rpm/lts/clickhouse-client-22.3.6.5.noarch.rpm |
|
|
|
wget https://packages.clickhouse.com/rpm/lts/clickhouse-common-static-22.3.6.5.x86_64.rpm |
|
|
|
wget https://mirrors.aliyun.com/clickhouse/rpm/lts/clickhouse-client-22.3.6.5.noarch.rpm |
|
|
|
wget https://mirrors.aliyun.com/clickhouse/rpm/lts/clickhouse-common-static-22.3.6.5.x86_64.rpm |
|
|
|
``` |
|
|
|
##### 安装 |
|
|
|
``` |
|
|
@ -101,6 +104,7 @@ clickhouse-client --host=<下图任一节点IP地址> --port=9000 --user=admin - |
|
|
|
<kbd> |
|
|
|
<img src="img/assignment5/adress.jpg"> |
|
|
|
</kbd> |
|
|
|
|
|
|
|
> 登录后将看到如下界面 |
|
|
|
<kbd> |
|
|
|
<img src="img/assignment5/login.jpg"> |
|
|
@ -161,11 +165,13 @@ SELECT * FROM ck_test.regression; |
|
|
|
sudo yum install python3 |
|
|
|
sudo yum install python3-pip |
|
|
|
``` |
|
|
|
安装clickhouse-driver |
|
|
|
安装clickhouse-driver,这里我们需要用阿里云镜像安装 |
|
|
|
``` |
|
|
|
pip3 install clickhouse-driver |
|
|
|
pip3 install --user -i https://mirrors.aliyun.com/pypi/simple clickhouse-driver |
|
|
|
``` |
|
|
|
|
|
|
|
可能会报未找到 gcc 命令的错误,运行 `sudo yum install -y gcc` 就好~ |
|
|
|
|
|
|
|
##### 2.1)安装完毕后运行python3,然后import clickhouse_driver,若没有报错,则说明clickhouse_driver安装成功。 |
|
|
|
<kbd> |
|
|
|
<img src="img/assignment5/run_python.jpg"> |
|
|
@ -174,7 +180,10 @@ pip3 install clickhouse-driver |
|
|
|
##### 2.2)quit()退出python3命令行,让我们运行几个Python代码来实现建表,插入,查询等操作。 |
|
|
|
|
|
|
|
> 建立createTable.py文件(若忘记创建文件命令可参考[实验一](https://gitea.shuishan.net.cn/xslu_dase_ecnu_edu_cn/cloud-computing-course/src/branch/master/Assignment1.md)),并复制如下代码。其中username,password,hostIP,port都要替换成你的数据仓库参数。 |
|
|
|
``` |
|
|
|
```python |
|
|
|
#!/usr/bin/env python |
|
|
|
# _*_ coding:utf-8 _*_ |
|
|
|
|
|
|
|
import clickhouse_driver |
|
|
|
|
|
|
|
# 建立连接 |
|
|
@ -206,7 +215,10 @@ python3 createTable.py |
|
|
|
``` |
|
|
|
|
|
|
|
> 向COMPANY表中添加一些记录。建立insertTable.py文件,复制如下代码并运行。 |
|
|
|
``` |
|
|
|
```python |
|
|
|
#!/usr/bin/env python |
|
|
|
# _*_ coding:utf-8 _*_ |
|
|
|
|
|
|
|
import clickhouse_driver |
|
|
|
|
|
|
|
# 建立连接 |
|
|
@ -221,7 +233,10 @@ conn.close() |
|
|
|
``` |
|
|
|
|
|
|
|
> 让我们查询一下刚刚建的表。建立selectTable.py文件,复制如下代码并运行。 |
|
|
|
``` |
|
|
|
```python |
|
|
|
#!/usr/bin/env python |
|
|
|
# _*_ coding:utf-8 _*_ |
|
|
|
|
|
|
|
import clickhouse_driver |
|
|
|
|
|
|
|
# 建立连接 |
|
|
|