DB2新建用户及数据库整个过程:
1.添加用户(root)
useradd -g users -d /home/用户名 -s /bin/bash -m 用户名
passwd 用户名
2.创建数据库(使用db2inst1用户)
$ db2 create database 数据库名using codeset GBK territory cn
(ps:db2每一个数据库对应一个操作系统用户,DB2的用户名必须和数据库名相同,否则用户连接数据库时,会报错:
)
3.给用户授予dba权限(使用db2inst1用户)
$ db2 connect to 数据库名
$ db2 grant dbadm on database to user <name>
4.创建schema(使用db2inst1用户)
$ db2 create schema <name> AUTHORIZATION <name>
5.用户配置(root)
$ cd /home/<name>
$ vi .bashrc,粘贴下面的代码
# The following three lines have been added by UDB DB2.
if [ -f /home/db2inst1/sqllib/db2profile ]; then
. /home/db2inst1/sqllib/db2profile
fi
(ps:新增用户无法像db2inst1一样使用db2命令,需进行此配置,否则会报错:db2 command not found)
测试:
$ db2
6.连接数据库(su到新建的用户)
#su - <name>
$db2 connect to 数据库名
7.设置当前会话的schema
$db2 set current schema <name>