Configure ksqlDB CLI
You can connect the ksqlDB CLI to one ksqlDB server per cluster.
There is no automatic failover of your CLI session to another ksqlDB Server if the original server that the CLI is connected to becomes unavailable. Any persistent queries you executed will continue to run in the ksqlDB cluster.
To connect the ksqlDB CLI to a cluster, run the following command with your
ksqlDB server URL specified (default is
Configure Per-session Properties¶
You can set the properties by using the ksqlDB CLI startup script argument
/bin/ksql --config-file <path/to/file> -- <ksql-server-URL> or by using the SET
statement from within the ksqlDB CLI session. For more information, see
Start the ksqlDB CLI.
Here are some common ksqlDB CLI properties that you can customize:
Connect to an Auth-enabled ksqlDB server¶
To connect to a ksqlDB server that requires authentication, supply your username and password when starting the ksqlDB CLI:
If you don't want to supply your password as part of the command, supply just the username, and you'll be prompted for your password when the command executes:
Execute Specific Statements and Quit¶
Rather than starting an interactive ksqlDB CLI session, you can pass the
ksqlDB CLI command a file of SQL statements to execute non-interactively
You can also use the
--execute option to pass individual statements as
part of the command itself:
Define Variables for Substitution in Commands¶
--define option allows you to specify values for variables for
use with variable substitution
within your SQL statements. The
--define option should be followed by a
string of the form
name=value and may be passed any number of times.
For example, the following command
is equivalent to starting an interactive ksqlDB CLI session and then issuing the following statements:
Defining variables as part of the ksqlDB CLI command is particularly useful
for variable substitution within files to be executed non-interactively.
Given the following contents of
Then the following command will create a stream backed by a topic with name