当前位置:网站首页>【clickhouse专栏】新建库角色用户初始化
【clickhouse专栏】新建库角色用户初始化
2022-06-11 14:00:00 【虚幻私塾】
优质资源分享
| 学习路线指引(点击解锁) | 知识定位 | 人群定位 |
|---|---|---|
| 🧡 Python实战微信订餐小程序 🧡 | 进阶级 | 本课程是python flask+微信小程序的完美结合,从项目搭建到腾讯云部署上线,打造一个全栈订餐系统。 |
| Python量化交易实战 | 入门级 | 手把手带你打造一个易扩展、更安全、效率更高的量化交易系统 |
一、创建新的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
推荐阅读
限于博文篇幅,更多精彩内容我就不一一列举了,推荐阅读
《原创精品视频及配套文档:springboot-已录制97节(免费)》
等等等等
边栏推荐
- About uni app configuration, app does not display the top title bar setting
- Today in history: Apple II comes out; Microsoft acquires gecad; The scientific and technological pioneer who invented the word "software engineering" was born
- VIM secondary replacement
- No delay / no delay live video instance effect cases
- Why does each running Department display that the database already exists, delete the database, and then succeed? Each running department must delete the database, and re run the whole successfully
- Kubernetes certificate collection
- Unity detects whether the object is within the viewing cone of the camera
- Container -- reverse content -- use of explosion, splicing, and inversion functions
- Can't understand kotlin source code? Starting with the contracts function~
- CVPR 2022 | 神经辐射场几何编辑方法NeRF-Editing
猜你喜欢

Easyexcel configuration and Application

Energy storage operation and configuration analysis of high proportion wind power system (realized by Matlab)

Business practice of volcano engine cloud database VEDB in bytes

Interview to build an aircraft carrier, screw on the job, pay
![InfoQ geek media's 15th anniversary essay solicitation - dynamic ranking of mobile terminal development [mui+flask+mongodb]](/img/92/50a92eb6b5c2ac3f58c499796a1e8c.png)
InfoQ geek media's 15th anniversary essay solicitation - dynamic ranking of mobile terminal development [mui+flask+mongodb]

Three level classification display

cadence SPB17.4 - allegro - allegro_ free_ viewer

JDBC连接池去做批量导入,每次运行500万数据,但是在中间就会出各种问题

Two small things, feel the gap with the great God

Ecplise cannot connect to SQL Server
随机推荐
Business practice of volcano engine cloud database VEDB in bytes
Question bank and answers for 2022 tool fitter (intermediate) operation certificate examination
VIM secondary replacement
SAP Spartacus checkout process uses URL paste to directly jump to delivery mode. Why the page cannot be opened
SAP Spartacus 中的 checkout(结帐) 设计
Is the securities account opened in qiniu safe? How to apply for a low commission stock account?
Vi LXD deployment of lab server for development records
How to manage the server to make the website stable and smooth
Just after the college entrance examination, I was confused and didn't know what to do? Tell me what I think
Pond (topology + priority queue)
SQL: how to use the data of purchase order and sales order to calculate commodity cost by moving weighted average method
tf. Data (II) -- parallelization tf data. Dataset generator
[the path of system analyst] collection of wrong topics of system analyst
JSP implementation of performance appraisal system for bank counter business
Hashicopy之nomad应用编排方案08(检测Job)
[Clickhouse] the clckhouse view can be inserted but not queried
Three level classification display
tp6基于whoops的异常接管(漂亮的界面)
Please, don't use enumeration types in external interfaces any more!
The application of machine learning in database cardinality estimation