跳到主要内容
版本:3.7.1

04 ClickHouse Setup

When you run ClickHouse manually with clickhouse server without explicitly specifying --config-file, it auto-generates a temporary config in the preprocessed_configs/ directory, and that config:

  • Ignores your /etc/clickhouse-server/config.xml
  • Overrides any user/password definitions
  • Makes it appear as if config changes don’t work

To run ClickHouse manually and set a password for the default user from the beginning — without relying on the default autogenerated config.

Create a custom temporary config file

If you're running ClickHouse from a custom directory or testing, do this:

  1. Create a config file my-config.xml in the current directory:
<clickhouse>
<listen_host>::</listen_host>
<logger>
<level>trace</level>
<console>true</console>
</logger>

<http_port>8123</http_port>
<tcp_port>9000</tcp_port>
<mysql_port>9004</mysql_port>

<path>./</path>

<mlock_executable>true</mlock_executable>

<users>
<default>
<password>password</password>

<networks>
<ip>::/0</ip>
</networks>

<profile>default</profile>
<quota>default</quota>

<access_management>1</access_management>
<named_collection_control>1</named_collection_control>
</default>
</users>

<profiles>
<default/>
</profiles>

<quotas>
<default/>
</quotas>
</clickhouse>
  1. Start ClickHouse with it:
clickhouse server --config-file=./my-config.xml
提示
  • The file in preprocessed_configs/ is a cache — do not edit it. Always change the original XML used by --config-file.
  • If you omit --config-file, ClickHouse uses embedded defaults with no password required.
  • If you’re testing, always provide an explicit config path to ensure reproducibility.

Verify Configuration Works

you’ll typically use a Python client like clickhouse-connect.

pip install clickhouse-connect
import clickhouse_connect

# Example parameters
host = "localhost"
port = 8123
user = "default"
password = "your_password" # Empty by default
dbname = "default"

client = clickhouse_connect.get_client(
host=host,
port=port,
username=user,
password=password,
database=dbname
)

# Run a test query
result = client.query("SELECT now()")
print(result.result_rows)
提示
  • clickhouse-connect uses HTTP protocol (port 8123).
  • clickhouse-driver uses the native TCP protocol (port 9000).
  • By default, ClickHouse does not require a password for the default user unless you've changed the config.