首页 > 代码库 > 新建aix实例
新建aix实例
请注意:为什么实例用户和实例名需要相同?
创建实例命令中,并没有实例用户的选项,但是系统却通过实例名找到该用户,
并在/home下的相关目录里建立了实例文件夹和文件(sqllib)。
-bash-3.2# cd instance 在instance目录下
-bash-3.2# ./db2icrt -u test test
DBI1070I Program db2icrt completed successfully.
-bash-3.2# cd /home
-bash-3.2# ls
ASKeyLinux dasusr1 esaadmin lost+found test
TT_DB db2fenc1 guest poka wqs
chong db2inst1 hegl poka01 yang
-bash-3.2# cd test
-bash-3.2# ls
.profile .sh_history sqllib
3.创建数据库
su - test
$ db2start
07/09/2014 11:04:01 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
$ db2 create db tcashman
DB20000I The CREATE DATABASE command completed successfully.
$ db2 connect to cashmant
Database Connection Information
Database server = DB2/AIX64 9.7.0
SQL authorization ID = TEST
Local database alias = CASHMANT
$ db2 list tables for all 显示该数据库所有的表
$ db2 drop db tcashman 删除数据库
DB20000I The DROP DATABASE command completed successfully.
$ db2stop
删除实例
-bash-3.2# cd /opt/IBM/db2/V9.7/instance
-以root身份执行 $DB2HOME/instance/db2idrop -f 实例名,注意一定要加-f,否则不会删除实例下面sqllib文件。如果不幸忘了,执行db2icrt,会报sqllib文件存在的错误,即使先删掉这个文件也不行,执行一下db2icrt,就会生成一部分sqllib,进入死胡同,呵呵,这个是由于用实例用户登录造成的,也许有个db2profile文件在登录时搞怪,该怎么办呢?看我的吧!用一个非实例的用户登录,su成root,然后再删掉sqllib,试试再db2icrt,问题解决了:)
bash-3.2# ./db2idrop -f test 注意一定要加-f,否则不会删除实例下面sqllib文件
DBI1324W Support of the -f command is deprecated. For
more information, see the DB2 Information Center.
DBI1070I Program db2idrop completed successfully.
-bash-3.2# cd test 此时test用户下sqllib文件已删除
-bash-3.2# ls
.profile .sh_history
-bash-3.2#
-bash-3.2$ db2 get dbm cfg 查看实例参数配置
TCP/IP Service name (SVCENAME) = (默认情况是无内容)
需要设置该参数信息,通过
$ cat /etc/services
db2c_db2inst1 50000/tcp // this is the connection port for instance DB2
DB2_db2inst1 60000/tcp // These ports reserved for DB2 Fast Communications Manager
DB2_db2inst1_1 60001/tcp
DB2_db2inst1_2 60002/tcp
DB2_db2inst1_END 60003/tcp
DB2_test 60004/tcp
DB2_test_1 60005/tcp
DB2_test_2 60006/tcp
DB2_test_END 60007/tcp
另外,在server端db2 get dbm cfg命令得出的下面内容里,db2c_DB2在services文件里对应的端口号就是server监听程序的端口号。TCP/IP Service name (SVCENAME) = db2cDB2。如果想要修改dbm参数,可以用如下命令:db2 update dbm cfg using SVCENAME db2cDB2_another。db2cDB2_another是事先定义好的端口变量。
注意到,这里SVCENAME是实例级变量,在语句db2 catalog tcpip node WEST remote 9.181.139.155 server 50000中,catalog的node由IP地址以及端口号确定,端口50000对应于实例级参数SVCENAME,所以,node的实际意义就是instance. 只是node是instance在网络上catalog的表示。
确保服务器端的db2已经启动:db2start
确保客户端DB2COMM设置为tcpip
先查看db2comm设置:db2set –all
如果没有设置这个注册表,执行db2set db2comm=tcpip
将SVCENAME设置成/etc/services中的端口号或者服务名了吗?
执行db2 get dbm cfg查看,找到SVCENAME,如果当前值不是服务器端的端口号或者服务名,进行更新设置
执行:db2 update dbm cfg SVCENAME db2inst1
注:db2inst1为服务名,这个在/etc/services文件中db2inst1 50000/tcp
一致
新建数据库
-bash-3.2$ db2 create database tcashman using codeset utf-8 territory cn
DB20000I The CREATE DATABASE command completed successfully.
-bash-3.2$ db2 connect to tcashman
Database Connection Information
Database server = DB2/AIX64 9.7.0
SQL authorization ID = DB2INST1
Local database alias = TCASHMAN
mkdir: 0653-357 Cannot access directory /home.
/home: The file access permissions do not allow the specified action. 问题是访问文件没有权限
-bash-3.2$ chmod 755 db2inst1
-bash-3.2$ cd /home/db2inst1
-bash-3.2$ ls
data db2inst1 export_sql fsms_8k_1 sqllib tempo
-bash-3.2$ cd data
-bash-3.2$ ls
-bash-3.2$ db2look -d cashman -e -a -x -i db2inst1 -w ‘1qaz!QAZ‘ -o db_714.sql
-- Generate statistics for all creators
-- Creating DDL for table(s)
-- Output is sent to file: db_714.sql
-bash-3.2$ ls
db_714.sql
导入表结构
db2 connect to tcashman
db2 -tvf /home/db2inst1/data/db_714.sql