当前位置:网站首页>【clickhouse专栏】新建库、用户及角色
【clickhouse专栏】新建库、用户及角色
2022-06-11 16:38:00 【字母哥哥】
一、创建新的database
clickhouse创建数据库的语法几乎和其他的关系型数据库是一样的,区别就是clickhouse存在集群cluster和库引擎engine的概念,可以根据需要进行指定。如果没有特殊需求,默认即可。
CREATE DATABASE [IF NOT EXISTS] db_name [ON CLUSTER cluster] [ENGINE = engine(...)]
在创建数据库的时候,我们首先要确认保存数据库文件的目录,对于clickhouse用户有读写的权限。如果你在安装的时候,没有修改数据库文件目录,默认的目录是/var/lib/clickhouse/。我们可以使用下面的命令,将该目录及其子目录的属主修改为clickhouse用户。
chown clickhouse /var/lib/clickhouse/ -R
完成上面的操作步骤之后,就可以通过clickhouse-client -m --password <你的密码>连接clichouse服务实例,创建数据库的SQL如下:
:) CREATE DATABASE acaidb;
创建数据库完成之后,使用show databases;命令看一下当前的clickhouse,有哪些database。(acaidb是我们自建的,default和system是clickhouse默认创建的database)
:) show databases;
┌─name────┐
│ acaidb │
│ default │
│ system │
└─────────┘
二、为default账户增加管理权限
ClickHouse默认创建一个数据库default,默认创建了一个用户default。我们现在针对default用户增加访问管理权限,因为该用户默认情况下是不具备管理员权限的,即:默认情况下,无法使用该用户添加角色、添加用户、以及其他权限管理操作。
所以为了让default用户的管理权限更大一些,我们修改 /etc/clickhouse-server/users.xml 文件,在users-> default标签中,将access_management的注释去掉。(在有些版本中其默认值是0,修改为1)
修改完成配置文件之后,重启clickhouse-server,使用如下命令:
clickhouse restart
三、创建角色及用户
创建角色
创建一个角色acaidb_rw, 该角色针对数据库acaidb具备读写权限。
CREATE ROLE acaidb_rw;
GRANT SELECT, INSERT, ALTER UPDATE, ALTER DELETE ON acaidb.* TO acaidb_rw;
如果让一个角色只允许select,不允许修改数据,下面的语句就可以。
CREATE ROLE acaidb_read;
GRANT SELECT ON acaidb.* TO acaidb_read;
创建普通账户并赋权
我们分别创建账户reader和writer,然后把只读角色ro分配给reader,把读写角色分配给writer。这样,reader拥有只读权限,writer拥有读写权限。新建一个数据库用户acai,并设置密码(将下文的<你的密码>替换)。并给用户acai赋予读写权限角色acaidb_rw 。
CREATE USER IF NOT EXISTS acai IDENTIFIED WITH sha256_password BY '<你的密码>';
GRANT acaidb_rw TO acai;
使用下列命令访问clickhouse数据,show databases得到acaidb,说明我们成功了。因为acai用户只能访问acaidb。
# clickhouse-client -m -u acai --password '<你的密码>' --query 'show databases;'
acaidb
推荐阅读
边栏推荐
- Laravel 8 uses passport for auth authentication and token issuance
- 2022 high altitude installation, maintenance and demolition test simulation 100 questions and online simulation test
- 2022年危险化学品经营单位主要负责人考试模拟100题及模拟考试
- Operation guide | how to select a collector on moonbeam and Moonriver
- Regression prediction | realization of RBF RBF neural network with multiple inputs and single output by MATLAB
- 基于ssm框架实现的企业进销存管理系统【源码+数据库+毕设】
- leetcode463. Perimeter of the island (simple)
- 什么是rs邮票纸?
- LeetCode——24. 两两交换链表中的节点(三指针)
- How unittest knows the execution time of each test case
猜你喜欢

开关电源电路图及原理12v分析-详细版

2022 safety officer-a certificate test question simulation test question bank simulation test platform operation

【pytest学习】pytest 用例执行失败后其他不再执行

The micro service failed to connect to the cloud sentinel console and the link blank problem occurred after the connection was successful (resolved)

RSP: An Empirical Study of remote sensing pre training

2022 molten welding and thermal cutting work license and simulation examination

How unittest knows the execution time of each test case

项目经理如何击退被工作汇报支配的恐惧感?

leetcode417. Pacific Atlantic current problems (medium)

2022年危险化学品经营单位主要负责人考试模拟100题及模拟考试
随机推荐
“is-a”,“has-a”,“like-a”
[ISITDTU 2019]EasyPHP
pycharm和anaconda的基础上解决Jupyter连接不上Kernel(内核)的问题--解决方案1
solr(一)solr的安装及权限控制
Time series prediction | MATLAB realizes future multi-step prediction of RBF RBF neural network time series
Oracle生成不重复字符串 sys_guid()与Mysql生成唯一值
美团获得小样本学习榜单FewCLUE第一!Prompt Learning+自训练实战
Leetcode 1974. 使用特殊打字机键入单词的最少时间(可以,一次过)
核密度估计(二维、三维)
2022 national question bank and mock examination for safety officer-b certificate
20 full knowledge maps of HD data analysis have been completed. It is strongly recommended to collect them!
2022熔化焊接与热切割上岗证题目及模拟考试
Report on the operation situation and future prospects of China's gear oil industry (2022-2028)
Laravel listening mode
2022 high voltage electrician special operation certificate examination question bank and online simulation examination
Enterprise purchase, sales and inventory management system based on SSM framework [source code + database + design]
开关电源电路图及原理12v分析-详细版
Zhenxiang, Huawei gives n+1 for voluntary resignation
2022g1 industrial boiler stoker test questions and simulation test
基于文本驱动用于创建和编辑图像(附源代码)