問題描述
db2 CREATE DATABASE XYZ
db2 DROP DATABASE XYZ
這些 db2 命令不支持在 db2cmd/db2clp 上為機器登錄用戶以外的特定用戶執行時指定用戶名/密碼.因此導致異常
These db2 commands which doesn't provide support to specify username/password while executing on db2cmd/db2clp for a specific user other than machine logged-in user. Hence result a exception
SQL1092N 請求的命令或操作失敗,因為用戶標識沒有執行請求的命令或操作的權限."
"SQL1092N The requested command or operation failed because the user ID does not have the authority to perform the requested command or operation."
當通過選擇以不同用戶身份運行"來運行相同的命令時,它可以正常工作.
And when the same commands run as by choosing 'Run as different user', it works properly.
- 但我需要使用 Java 代碼中的相同機制,但不知道如何使用.是否可以以不同的用戶表單 Java 代碼打開已安裝的 db2 的 clp??
- 是否可以在創建/刪除命令中關聯用戶名/密碼?
推薦答案
在 CLP 中,您可以首先使用所需的任何用戶 ID ATTACH
到實例,然后發出 CREATE DATABASE
命令.
From the CLP you can first ATTACH
to the instance using whatever user ID you need, and then issue the CREATE DATABASE
command.
如果實例在您的本地機器上運行,您只需像這樣附加:
If the instance is running on your local machine, you just attach like this:
$ db2 attach to db2inst1 user db2inst1
Enter current password for db2inst1:
Instance Attachment Information
Instance server = DB2/LINUXX8664 9.7.5
Authorization ID = DB2INST1
Local instance alias = DB2INST1
如果實例在遠程服務器上運行,則附加到您在數據庫目錄中定義的節點名稱":
If the instance is running on a remote server, you attach to the "node name" that you have defined in your database catalog:
$ db2 list db directory
System Database Directory
Number of entries in the directory = 1
Database 1 entry:
Database alias = SAMPLE
Database name = SAMPLE
Node name = SRV01
Database release level = d.00
Comment =
Directory entry type = Remote
Catalog database partition number = -1
Alternate server hostname =
Alternate server port number =
在本例中,list database directory
的輸出中顯示的節點名稱為 SRV01
,因此您可以使用以下命令進行附加:db2 attach to srv01 user <用戶名>
.
In this example, the Node Name shown in the output from list database directory
is SRV01
, so you would attach using: db2 attach to srv01 user <username>
.
這篇關于為機器登錄用戶以外的特定用戶運行創建/刪除 DB2 數據庫命令的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!