Linux下DB2SQL1024N A database connection does not exist.
前几天在RedHat Linux 6安装了DB2V10.5,安装过程没报任何错误,但是在后来测试的时候发现一个问题如下:
[db2inst@myrac1 ~]$ db2 connect to sldd user db2inst using db2inst
Database Connection Information
Database server = DB2/LINUX 10.5.2
SQL authorization ID = DB2INST
Local database alias = SLDD
[db2inst@myrac1 ~]$db2 list tables
SQL1024N A database connection does not exist. SQLSTATE=08003
[db2inst@myrac1 ~]$db2 get connection state
全是--,没有连接信息
比较奇怪的是在CLP下么有问题
[db2inst@myrac1 ~]$ db2
(c) Copyright IBM Corporation 1993,2007
Command Line Processor for DB2 Client 10.5.2
You can issue database manager commands and SQL statements from the command
prompt. For example:
db2 => connect to sample
db2 => bind sample.bnd
For general help, type: ?.
For command help, type: ? command, where command can be
the first few keywords of a database manager command. For example:
? CATALOG DATABASE for help on the CATALOG DATABASE command
? CATALOG for help on all of the CATALOG commands.
To exit db2 interactive mode, type QUIT at the command prompt. Outside
interactive mode, all commands must be prefixed with 'db2'.
To list the current command option settings, type LIST COMMAND OPTIONS.
For more detailed help, refer to the Online Reference Manual.
db2 => connect to sldd user db2inst using db2inst
Database Connection Information
Database server = DB2/LINUX 10.5.2
SQL authorization ID = DB2INST
Local database alias = SLDD
db2 => list tables
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
ADVISE_INDEX DB2INST T 2014-02-11-00.30.51.141096
ADVISE_INSTANCE DB2INST T 2014-02-11-00.30.50.725861
ADVISE_MQT DB2INST T 2014-02-11-00.30.53.438431
ADVISE_PARTITION DB2INST T 2014-02-11-00.30.54.567669
ADVISE_TABLE DB2INST T 2014-02-11-00.30.55.366786
ADVISE_WORKLOAD DB2INST T 2014-02-11-00.30.52.033549
DX_AJ_IND_STD DB2INST T 2014-02-11-00.30.25.714475
问题考虑:
1.是不是因为实例用户是db2inst用户而不是db2inst1呢?
经查证不是这个原因,虽然DB2的默认实例用户是db2inst1,但是可以创建其他的实例用户
2.DB2COMM=TCPIP的原因?
设置db2set DB2COMM=TCPIP,问题依旧
最后,在网上找到了解决方案:
[root@myrac1 ~]# vi /etc/services
添加如下两行
DB2_db2inst 60006/tcp
DB2_db2inst_1 60007/tcp
DB2_db2inst_2 60008/tcp
DB2_db2inst_3 60009/tcp
DB2_db2inst_4 60010/tcp
DB2_db2inst_END 60011/tcp
DB2_db2inst1 60012/tcp
db2c_db2inst 50005/tcp db2inst实例监听端口
db2i_db2inst 50009/tcp db2inst实例中断端口
DB2_db2inst1_1 60013/tcp
DB2_db2inst1_2 60014/tcp
DB2_db2inst1_3 60015/tcp
[db2inst@myrac1 ~]$ db2 connect to sldd user db2inst using db2inst
Database Connection Information
Database server = DB2/LINUX 10.5.2
SQL authorization ID = DB2INST
Local database alias = SLDD
[db2inst@myrac1 ~]$ db2 list tables
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
ADVISE_INDEX DB2INST T 2014-02-11-00.30.51.141096
ADVISE_INSTANCE DB2INST T 2014-02-11-00.30.50.725861
ADVISE_MQT DB2INST T 2014-02-11-00.30.53.438431
ADVISE_PARTITION DB2INST T 2014-02-11-00.30.54.567669