How to Change Passwords in ClickHouse

Galaxy Glossary

How do I change a user password in ClickHouse?

ALTER USER or CREATE USER ... IDENTIFIED BY changes a ClickHouse user’s password without service downtime.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Description

Table of Contents

Why change a ClickHouse password?

Rotating credentials limits exposure if a password leaks and meets compliance policies. ClickHouse lets you update passwords online with a simple SQL statement.

What SQL syntax changes a password?

Use ALTER USER when the user already exists. Use CREATE USER with IF NOT EXISTS when setting the first password. Both support multiple authentication methods.

Is a restart required?

No.Password changes take effect instantly across the cluster when replicated via users.xml or RBAC.

How do I alter an existing user?

Run ALTER USER analytics IDENTIFIED BY 'N3wS3cret!';. Replace the string with a strong password. Session re-authentication occurs on the next connection.

Can I use hashed passwords?

Yes. Supply IDENTIFIED WITH sha256_hash BY 'hex_hash' for SHA-256 or double_sha1_password for double SHA-1. Hash locally; never send plain text if policy forbids it.

Example in an ecommerce database

You have analysts querying Customers and Orders.To rotate their password at quarter-end:

ALTER USER analyst IDENTIFIED BY 'Q1_2025_Sales^';

They keep access to views joining CustomersOrdersOrderItems.

Best practices

1. Use a password manager to generate 16+ character strings.
2. Restrict users to specific databases with GRANT after changing passwords.
3. Automate rotation via CI pipelines running ClickHouse client scripts.

Common mistakes

Omitting the cluster clause

On multi-node setups managed by RBAC, append ON CLUSTER my_cluster or the change applies only locally.

Forgetting to flush cache

Older clients may hold persistent sessions.Close open connections or wait for idle timeout to force re-login.

Quick checklist before running

✔ Confirm you’re on the correct cluster.
✔ Verify user name spelling.
✔ Store the new password securely.
✔ Retest application connectivity.

.

Why How to Change Passwords in ClickHouse is important

How to Change Passwords in ClickHouse Example Usage


-- Quarterly rotation for reporting role
ALTER USER reporting_app ON CLUSTER company_cluster IDENTIFIED WITH sha256_hash BY '12ab34cd56ef7890...';
-- reporting_app continues to query
SELECT c.id, c.name, SUM(oi.quantity * p.price) AS lifetime_value
FROM Customers c
JOIN Orders o  ON o.customer_id = c.id
JOIN OrderItems oi ON oi.order_id = o.id
JOIN Products p    ON p.id = oi.product_id
GROUP BY c.id, c.name;

How to Change Passwords in ClickHouse Syntax


-- Change existing user's password
ALTER USER [IF EXISTS] user_name
    [ON CLUSTER cluster_name]
    IDENTIFIED {BY 'plain_pw' | WITH plaintext_password BY 'plain_pw' | WITH sha256_hash BY 'hex_hash' | WITH double_sha1_hash BY 'hex_hash'};

-- Create user if missing and set password in one step
CREATE USER IF NOT EXISTS user_name
    [ON CLUSTER cluster_name]
    IDENTIFIED BY 'plain_pw';

-- Ecommerce example: rotate analyst password across a cluster
ALTER USER analyst ON CLUSTER company_cluster IDENTIFIED BY 'Q1_2025_Sales^';

Common Mistakes

Frequently Asked Questions (FAQs)

Can I rotate passwords automatically?

Yes. Integrate ALTER USER commands into CI/CD jobs or Ansible playbooks to run scheduled rotations.

Does altering a password kill existing sessions?

No immediate kill occurs, but new queries after the password expires must reconnect. Manually terminate old sessions if required via SYSTEM KILL QUERY.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.