How to connect to and query a DB2 database in Linux?
To connect and query a DB2 database on Linux, you can follow these steps:
- Install the DB2 driver: You must first install the DB2 database driver in order to connect to the database. You can download the appropriate driver for your system from the IBM website.
- Set up the DB2 environment variables: On your Linux system, you will need to configure some environment variables to set up DB2. You can add the following content to the db2profile file.
export DB2HOME=<DB2安装目录>
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DB2HOME/lib
export PATH=$PATH:$DB2HOME/bin
Please make the necessary changes based on your DB2 installation directory.
- Connect to DB2 database: Use the following command to connect to the DB2 database:
db2 connect to <数据库名> user <用户名> using <密码>
Please replace
- DB2
db2 "select * from <表名>"
Please replace