1. 什么是ClickHouse?

  2. 安装clickhouse

     sudo yum install -y yum-utils
     sudo yum-config-manager --add-repo https://packages.clickhouse.com/rpm/clickhouse.repo
     sudo yum install -y clickhouse-server clickhouse-client
    
    • 启动clickhouse: sudo /etc/init.d/clickhouse-server start
    • 进入clickhouse客户端:clickhouse-client # or "clickhouse-client --password" if you set up a password.
  3. 修改clickhouse配置文件

    • 允许远程访问: vi /etc/clickhouse-server/config.xml,将<listen_host>::</listen_host>取消注释
    • 设置访问密码:vi /etc/clickhouse-server/users.xml,在password标签中设置自己的密码
    • 重启服务:service clickhouse-server restart
    • 防火墙放行指定端口:firewall-cmd --zone=public --add-port= 8123/tcp --permanent,重启防火墙:firewall-cmd --reload
  4. 下载clickhose客户端工具

  5. 创建clickhouse测试数据库

    • CREATE DATABASE IF NOT EXISTS test_db;
  6. 导入官网上给的测试数据

     clickhouse-client --format_csv_allow_single_quotes 0 --input_format_null_as_default 0 --query "INSERT INTO test_db.dish FORMAT CSVWithNames" < Dish.csv
     clickhouse-client --format_csv_allow_single_quotes 0 --input_format_null_as_default 0 --query "INSERT INTO test_db.menu FORMAT CSVWithNames" < Menu.csv
     clickhouse-client --format_csv_allow_single_quotes 0 --input_format_null_as_default 0 --query "INSERT INTO test_db.menu_page FORMAT CSVWithNames" < MenuPage.csv
     clickhouse-client --format_csv_allow_single_quotes 0 --input_format_null_as_default 0 --date_time_input_format best_effort --query "INSERT INTO test_db.menu_item FORMAT CSVWithNames" < MenuItem.csv
    
  7. SpringBoot项目集成clickhouse

    • 引入clickhouse-jdbc依赖
         <dependency>
             <groupId>com.clickhouse</groupId>
             <artifactId>clickhouse-jdbc</artifactId>
             <version>0.3.2</version>
         </dependency>
    
    • application.yml配置文件中配置clickhouse地址
           url: jdbc:clickhouse://127.0.0.1:8123/test_db?useSSL=false
           username: default
           password: reminis@2023
           driver-class-name: com.clickhouse.jdbc.ClickHouseDriver   
    
    • 通过mybatis-plus或其它ORM框架对clickhosue数据库中的表进行crud操作
  8. 把其它数据源的数据导入clickhouse

02-20 12:01