db2cli - Db2 interactive CLI command
Starts the interactive call level interface (CLI) environment for design and prototyping in CLI.
The db2cli command is located in the bin subdirectory of the directory where you installed IBM® data server product. On UNIX and Linux® operating systems, the db2cli command is located in the home_dir/sqllib/bin directory, where home_dir is the home directory of the instance owner. On Windows operating systems, the command is located in the DB2PATH\bin directory, where DB2PATH is the installation location of the Db2 copy.
Authorization
None
Required connection
None
Command syntax
Command parameters
- bind
Binds the specified filename against the target database. The db2cli bind command first connects to the target database with the information provided in the db2cli bind command parameters then performs the bind action. Bind files have the extension .bnd.
- filename
- The filename can be a name of bind file or list file that contains the name
of several bind files. If a list file is specified, the @ character must be prefixed to the list
file name. The fully qualified bind file name can be specified within a double quotation mark.
When just the bind file name without any path is specified, the file would be first searched for in the current directory. If the file is found, it would be picked up and the package would be created. If the file is not found in the current directory, then the file would be automatically picked up from the instance or install path.
- -dsn dsn_name
- Specifies the data source name (DSN) you bind to. When using this
bind option, all information except for a valid user ID and password
required to connect to the target database must be present in:
- The data source name section in the db2cli.ini file.
- The database section or the DSN section in the db2dsdriver.cfg file.
- The local catalog entry.
- -database database:server:port
- Specifies the database name, server name, and port number you bind to. You must use a colon to separate the database name, server name, and port number. The server name must consist of a fully qualified domain name (FQDN), for example, TESTDB:dbserver.example.com:19677.
- -user username
- Specifies the user name to use for the connection.
- -passwd password
- Specifies the password to use for the connection.
- -options "various_bind_options"
- Specifies the bind options and their values. The following bind
options are available:
- BLOCKING
- COLLECTION
- ENCODING
- GENERIC
- GRANT
- GRANT_ROLE
- ISOLATION
- KEEPDYNAMIC
- REOPT
- -help
- Shows the help information that is related to the usage of the bind parameter.
- registerdsn
Specifies the db2cli register DSN mode. Use this command parameter to register a DSN in the Windows operating system.
- -add dsn_name|-alldsn
- Adds system or user ODBC data sources to the Microsoft ODBC Data Source Administrator. The description will be added
into registry only if the description value is present for that DSN in the
db2dsdriver.cfg file or in the db2cli.ini file.
- dsn_name
- Indicates the DSN to register. The value of dsn_name must be the DSN that is defined in the db2cli.ini file or the DSN alias that is defined indb2dsdriver.cfg file and cannot be a DBALIAS name. The -add dsn-name parameter adds data sources for cataloged databases that are available in the local database directory. The dsn-name can indicate a data source that is defined in the db2cli.ini or the DSN aliases that are defined in thedb2dsdriver.cfg file, and a database alias in the local database directory in IBM Data Server clients. If the dsn_name has white space in the middle, surround it with double quotation marks.
- -dsn
- Enables the user to specify a DSN name that needs to be added to the Microsoft ODBC Data Source Administrator. The db2cli registerdsn -add -dsn command is available on Windows operating systems.
- -alldsn
- Registers all the data sources that are defined in the db2cli.ini file, the DSN aliases
defined in the
db2dsdriver.cfg file, and the local database catalog. You must use this
parameter with the -add parameter.
- -includeldap
- Registers all the data sources that are specified in the LDAP server, the db2cli.ini file, the db2dsdriver.cfg file, and the local database catalog. Ensure that you can connect successfully to the LDAP server by configuring the LDAP section in the IBM data server driver configuration file or configuring the LDAP connection in your Windows environment.
- -user
- Registers data sources as user ODBC data sources. If no parameter is specified, data sources are registered as user ODBC data sources.
- -system
- Registers data sources as system ODBC data sources.
- -remove dsn_name
- Removes a
system or user ODBC data source from the Microsoft ODBC
Data Source Administrator. If the dsn_name has white space in the middle,
surround it with double quotation
marks.
- -alldsn
- Removes all the user or system ODBC data source entries of a specified Db2 copy from the Microsoft ODBC Data Source Administrator. The db2cli register -remove -alldsn command is available on Windows operating systems.
- -copyname copy_name
- Removes the user or system ODBC data source entries of a specified Db2 copy from the Microsoft ODBC Data Source Administrator. If you do not specify a copy name, the current copy name is used. The current copy name is the copy name of the client where the db2cli utility is from. If you specify the -copyname option with the -alldsn option, all data source entries in the Microsoft ODBC Data Source Administrator are removed from the specified Db2 copy. The db2cli register -remove -copyname command is available on Windows operating systems.
- -allcopies
- Removes all the user or system ODBC data source entries of all the Db2 copies from the Microsoft ODBC Data Source Administrator. Unless you also specify the -force option, you are prompted to confirm that you want to remove all ODBC data source entries. The db2cli register -remove -allcopies command is available on Windows operating systems.
- -force
- Removes all the user or system ODBC data source entries without prompting you for confirmation. You can use the -force option only with the -allcopies option. The db2cli register -remove -allcopies -force command is available on Windows operating systems.
- -dsn
- Specifies a DSN name to remove from the Microsoft ODBC Data Source Administrator. The db2cli register -remove -dsn command is available on Windows operating systems. The default option is -user, which removes a user DSN. You must specify the -system option to remove a system DSN.
- -list
- Lists all the system or user IBM Data
Server ODBC data sources that are registered in the Microsoft ODBC Data Source Administrator.
- -copyname copy_name
- Lists the user or system ODBC data source entries of the specified Db2 copy in the Microsoft ODBC Data Source Administrator. If you do not specify the copy name, the current copy name is used. The current copy name is the copy name of the client where the db2cli utility is from. The db2cli register -list -copyname command is available on Windows operating systems.
- -allcopies
- Lists all the user or system ODBC data source entries of all the Db2 copies in the Microsoft ODBC Data Source Administrator. The db2cli register -list -allcopies command is available on Windows operating systems.
- -help
- Shows the help information that is related to the usage of the registerdsn parameter. Note: To add, remove, or list 32-bit ODBC data source entries on 64-bit Windows machines, use db2cli32 command.
- csc -info
- Displays connection supervisor client (CSC) information. A CSC is a dynamically loadable library that CLI uses for the purpose of end-to-end monitoring.
- -execsql
Executes or prepares the SQL statements specified in an input file. Can also save output to a file.
- -execute
- Specifies that the SQL statements in the SQL script file are prepared and run. This is the default if no parameter is specified. Results are displayed in the console. To save the output to a file, specify the option -output with the absolute or relative path of the file. SQL statements in the SQL script file cannot have parameter markers.
- -prepareonly
- Specifies that the SQL statements in the file specified by the -inputSql option are prepared but not run. Use this option to check the syntax of the SQL statements without running the statements.
- -commentstart comment_indicator
- Specifies the character combination that appear at the beginning of a line to indicate a comment line. The default value of comment_indicator is two dashes (--). If a comment spans multiple lines, start each line with the comment_indicator character combination. The maximum length of a comment line is 128 characters. In the input SQL file, the text after the comment characters can contain statement cursor attributes. The cursor attributes apply to the SQL statement immediately following the comment.
- -connstring string
- Specifies the
database name, server, and port number of the target database. The information must be specified in
the format as defined by the
InConnectionString
argument in the SQLDriverConnect API function. For example:
.DATABASE=SAMPLE;HOSTNAME=test.ibm.com;PORT=50000;UID=db2user;PWD=db2pwd
- -dsn dsn_name
- Specifies the data source name in the db2cli.ini file or the dsn alias defined in db2dsdriver.cfg file.. If the dsn_name has white space in the middle, surround it with double quotation marks.
- -help
- Displays summary usage information.
- -inputsql sqlfile
- Specifies the input file that contains SQL statements. The value of sqlfile
is the absolute or relative path of the file. The SQL statements in the file are separated by a
delimiter. Only preparable statements are used. Db2 commands
such as DESCRIBE TABLE and BIND are not allowed.
Only SQL statements and comments can be in the input SQL file. The file cannot contain CLI specific attributes or keywords. Batch SQL statements are not supported.
- -outfile outputfile
- Specifies the absolute or relative path of the file to store the output results. When this option is not specified, the results are displayed in the console.
- -passwd password
- Specifies the password to use for authenticating with the database.
- -statementdelimiter delimiter
- Specifies the character combination that is used in the input SQL file to separate statements. The default value of delimiter is a carriage return.
- -user username
- Specifies the user for authenticating with the database.
- install
Registers or unregisters the IBM Data Server Driver for ODBC and CLI in the Windows registry.
- -setup
- Registers the IBM Data Server Driver for ODBC and CLI under ODBC in the Windows registry. This parameter also creates configuration folders (cfg, cfgcache, db2dump) and sample configuration file in the default application data path.
- -appdatapath <path name>
- Creates configuration folders (cfg, cfgcache, db2dump) and sample configuration files in the path name.
- -cleanup
- Unregisters the current IBM Data
Server Driver for ODBC and CLI from the Windows registry under ODBC. The cleanup
then removes the folders, configuration sample files, and license
management files that are created at the application data path for
the current installation. Any user-created files or folders are not
removed unless you specify the –force option.
- -force
- When specified with the –cleanup option, the entire install-specific folder is removed from the application data path. This folder belongs to this installation only. Any user-created files or folders in this folder are removed without any prompt or warning.
- -help
- Shows the help information that is related to the usage of the install parameter.
- writecfg add|remove
- Updates the db2dsdriver.cfg configuration
file.
- add -dsn | -database | -parameter[s]
- Adds information about the DSN, database, or parameters to the db2dsdriver.cfg configuration
file.
- -dsn dsn_name [-description dsn_description] -database db_name -host host_name -port port_number
- Specifies the DSN alias name along with an optional description value. You can add or update the
parameter elements, the session global variable parameter element, or the entire
-dsn subsection for the DSN alias in the configuration file. If the
dsn_name has white space in the middle, surround it with double quotation marks.
The -dsn
dsn_name option is mandatory for -description
dsn_description.
If the -dsn subsection with the dsn_name as the DSN alias does not exist in the configuration file, a new -dsn subsection in the dsncollection section is added.
If a -dsn subsection with the dsn_name as the DSN alias exists in the configuration file, the new parameters or session global variables information is appended to the existing -dsn subsection.
If a -database subsection with the same db_name information exists in the db2dsdriver.cfg configuration file, the specified parameter element is appended to the -database subsection. Otherwise, the specified parameter elements or the session global variable parameter elements are added to a new -database subsection.
- -database db_name -host host_name -port port_number
- Specifies
the connection information for a <database> subsection. This
information consists of the database name, the host name where the
database is located, and the port number of the database server.
If a <database> subsection with the same db_name information exists in the db2dsdriver.cfg configuration file, the specified parameter element is appended to the <database> subsection. Otherwise, the specified parameter elements or the session global variable parameter elements are added to a new <database> subsection.
- -parameter[s]
parameter_name1=par1_val[;...;parN=parN_val]
- Specifies the parameter information to add or update a parameter
element for all databases and DSNs in the db2dsdriver.cfg configuration
file.
To add a parameter to the global <parameters> section, specify the parameter information without indicating a database or a data source.
If you specify a new parameter element that is not found in the <parameters> subsection of the db2dsdriver.cfg configuration file, a new parameter element is added to the <parameters> subsection.
If the specified parameter element is already present in the configuration file, the existing parameter value in the <parameters> subsection is updated with the value that you specify with the -parameter[s] option.
Special characters, such as path separators in the value, must be preceded by the escape character
\
.The db2cli writecfg command does not verify the syntax or validate the value of the specified parameter.
- -sessionglobalvariables globvar_string
-
Where globvar_string is in the following format:
globvar_name=globvar_value[;...;globvar_nameN=globvarN_value]
Specifies the parameter information to add or update a parameter element for all databases or DSNs in the db2dsdriver.cfg configuration file.
If you specify a new session global variable parameter that is not found in the <parameters> subsection of the db2dsdriver.cfg configuration file, a new session global variable parameter element is added to the <parameters> subsection.
If the specified session global variable parameter element is already present in the configuration file, the session global variable value in the <parameters> subsection is updated with the value that you specify with the -sessionglobalvariables option.
Special characters, such as path separators in the value, must be preceded by the escape character
\
.The db2cli writecfg command does not verify the syntax or validate the value of the specified parameter.
- -specialregisters register_string
-
Where register_string is in the following format:
register_name=register_value[;...;register_nameN=registerN_value]
Specifies special register information that is used to add or update a parameter element for all databases in the db2dsdriver.cfg configuration file.
If you specify a special register parameter that is not in the <parameters> subsection of the db2dsdriver.cfg configuration file, a special register parameter element is added to the <parameters> subsection. If the specified special register parameter element is already in the configuration file, the special register value in the <parameters> subsection is updated with the value that you specify for the -specialregisters parameter.
You must precede any special characters in the special register value (registerN_value) with the escape character
\
.The db2cli writecfg command does not verify the syntax or validate the value of the specified special register parameter.
- remove -dsn| -database | -parameter[s]
- Removes information about the DSN, database, or parameters from
the db2dsdriver.cfg configuration file.
- -dsn dsn_name
- Specifies the DSN for which you want to remove the parameter elements,
the session global variable parameter element, or the entire <dsn>
subsection in the configuration file. If the dsn_name has white space in the middle, surround it with double quotation marks.
To remove parameter elements or session global variable parameter elements information, specify the corresponding DSN and the parameter or session global variable information.
To remove the entire data source subsection, specify only the DSN without any parameters or session global variables information.
- -database db_name -host host_name -port port_number
- Specifies the database name for which you want to remove parameter
elements, session global variable parameter elements, or the entire <database>
subsection in the configuration file.
To remove parameter elements or session global variable parameter elements information, specify the corresponding database name and the parameter or session global variable information.
To remove the entire database subsection, specify only the database name without any parameter or session global variable information.
- -parameter[s]
parameter_name1[;...;parameter_nameN]
- Specifies the parameter information that is to be removed from
the <parameters> section in the db2dsdriver.cfg configuration
file.
If the indicated parameter is not in the <parameters> section of the configuration file, no action is taken.
- -sessionglobalvariables
globvar_name[;...;globvar_nameN]
- Specifies the session global variable information that is to be
removed from the <parameters> section in the db2dsdriver.cfg configuration
file.
If the indicated session global variable is not in the <parameters> section of the configuration file, no action is taken.
- -sessionglobalvariables -force
- Removes all the session global variable information from the <parameters> section in the db2dsdriver.cfg configuration file. No action is taken if the session global variables are not in the <parameters> subsection.
- -specialregisters
register_name=register_value[;...;register_nameN=registerN_value]
- Specifies the special register information to remove from the <parameters> section in the db2dsdriver.cfg configuration file. If the indicated special register is not in the <parameters> subsection of the configuration file, no action is taken.
- -specialregisters -force
- Removes all the special register information from the <parameters> section in the db2dsdriver.cfg configuration file. No action is taken if the special registers are not in the <parameters> subsection.
- -help
- Shows the help information that is related to the usage of the writecfg parameter.
- refreshldap
- Updates and appends all configuration information in the IBM data server driver configuration file (db2dsdriver.cfg) with the
configuration information that are specified on the Lightweight Directory Access Protocol (LDAP)
server. The db2cli refreshldap command retrieves the configuration information
that is specified for the current user ID, which is used to connect to the LDAP server. All DSN
entries in the IBM data server driver configuration file that
were created using the db2cli refreshldap command contains the
LDAP="1" attribute.
The authentication type that is defined for a database in the LDAP server is appended or updated to the
<dsn>
section for that DSN alias in the IBM data server driver configuration file.The Protocol parameter that is defined for a database in the LDAP server is appended or updated to the
The following table lists the DCS parameters and equivalent keywords that are supported in the IBM data server driver configuration file. Only the listed DCS parameters can be appended or updated with the refreshldap option.<dsn>
section for that DSN alias only if the value is not TCPIP.All supported DCS parameters except the SYSPLEX parameter are appended or updated to theTable 1. DCS parameters and equivalent IBM data server driver configuration keywords DCS parameter Equivalent keyword map-file SQLCODEMAP INTERRUPT_ENABLED InterruptProcessingMode SYSPLEX ConnectionLevelLoadBalancing BIDI BiDiCCSID <dsn>
section. The SYSPLEX parameter that is present in the LDAP server is appended or updated to the corresponding <database> section. When you are using the refreshldap option to update the IBM data server driver configuration file, you can avoid unexpected behaviors by not configuring the db2cli.ini file. The db2cli.ini file configuration takes precedences over the IBM data server driver configuration file.The db2cli refreshldap command creates the IBM data server driver configuration file if it is not present.
The db2cli refreshldap command updates the IBM data server driver configuration file with keywords that are equivalent to the CLI keywords, which are specified in the LDAP server. Any CLI keywords that are specified on the LDAP server that does not have equivalent IBM data server driver configuration keyword results in a warning message. Any gateway settings on the LDAP server, which are specified through GWNODE option are not appended or updated, and results in a warning message. The alternate server settings on the LDAP server are not appended or updated, and results in a warning message.If there is a DSN entry on the LDAP server that matches an existing DSN entry in the IBM data server driver configuration file that is not created from the LDAP server entry (without the LDAP="1" attribute), a warning is returned and the DSN entry is not updated.
If multiple DSN entries exist on the IBM data server driver configuration file for a same database but with different alias, only the DSN entries that were created from the LDAP server entry (with the LDAP="1" attribute) are removed when the DSN entry on the LDAP server is deleted.The db2cli refreshldap command can be issued with any of the IBM Db2 Data Server products and the IBM Db2 database products.
The db2cli refreshldap command is similar to the REFRESH LDAP IMMEDIATE ALL command that can be issued from the IBM Data Server Client, IBM Data Server Runtime Client or IBM database server products.- -global
- Updates and appends all configuration information in the IBM data server driver configuration file with the global configuration information, which is specified for all the user IDs, on the LDAP server.
- -help
- Shows the db2cli command help information.
Usage notes
The interactive CLI interface consists of a set of commands that you can use to design, prototype, and test CLI function calls. It is a testing tool that is provided for the convenience of those programmers who want to use it, and IBM makes no guarantees about its performance. This interface is not intended for users, and so does not have extensive error-checking capabilities.
- CLI commands
- Commands that correspond to (and have the same name as) each of the function calls that is supported by CLI.
- Support commands
- Commands that do not have an equivalent CLI function.
- Additional modes
- You can use the additional modes for the db2cli command to validate and test the CLI environment configuration.
You can issue commands interactively or from within a file. Similarly, you can display the command output on the terminal or write it to a file. A useful feature of the IBM Data Server Driver for ODBC and CLI is the ability to capture all of the commands that are entered during a session, and to write them to a file, thus creating a command script that you can rerun at a later time.
For IBM Data Server client packages on Windows 64-bit operating systems, the 32-bit version of db2cli (db2cli32.exe) is supported in addition to the 64-bit version of the db2cli command.
SQL statements are executed by using the SQLExecDirect() function. When executing SQL statements, the db2cli execsql command uses the database settings specified in the db2cli.ini and db2dsdriver.cfg files.
Error messages returned by the db2cli command are formatted using the same format as the SQLGetDiagRec() function.
- Catalog the server node. For more information, see "Cataloging a TCP/IP node from a client using the CLP".
- Catalog the database that you want to connect to. For more information, see "Cataloging a database from a client by using the CLP".
- (Optional) Catalog the Database Connection Services (DCS) directory. For more information, see "Catalog DCS database command".
- Register the DSN by using the db2cli interactive
tool.
- For 32-bit ODBC DSN, use the db2cli32 command.
- For 64-bit ODBC DSN, use the db2cli command.
For 32-bit installations, the db2cli command by default registers only 32-bit DSN.
The DSN that you want to register must be in the db2cli.ini or the db2dsdriver.cfg file.