Search code examples
clickhouse

How to setup an admin account for Clickhouse?


I'm running Clickhouse in a docker container on a Windows host. I tried to create an account towards making it an admin account. It looks like the default user does not have permission to create other accounts. How can I get around this error and create an admin account?

docker-compose exec -T dash-clickhouse clickhouse-client --query="CREATE USER 'foo' IDENTIFIED WITH sha256_password BY 'bar'"

gave the error

Received exception from server (version 20.7.2):
Code: 497. DB::Exception: Received from localhost:9000. DB::Exception: default: Not enough privileges. To execute this query it's necessary to have the grant CREATE USER ON *.*.

Solution

  • To fix it need to enable access_management-setting in the users.xml file:

    #  execute an interactive bash shell on the container
    docker-compose exec {container_name} bash
    # docker exec -it {container_name} bash
    
    # install preferable text editor (i prefer using 'nano')
    apt-get update
    apt-get install nano
    
    # open file users.xml in the editor
    nano /etc/clickhouse-server/users.xml
    

    Uncomment the access_management-setting for the default user and save changes:

    ..
    <!-- User can create other users and grant rights to them. -->
    <!-- <access_management>1</access_management> -->
    ..