1.创建用户(切换到root用户下操作)

useradd -g users -d /home/qinys -s /bin/bash -m qinys



2.修改密码

passwd qinys


备注:此处修改的密码与用户名一致:qinys

3.启动数据库

Linux:/ # su db2inst1
db2inst1@Linux:/> db2start
02/07/2018 04:43:57 0 0 SQL1026N The database manager is already active.
SQL1026N The database manager is already active.



4.创建数据库

db2inst1@Linux:/> db2 create database QinDB using codeset GBK territory cn
DB20000I The CREATE DATABASE command completed successfully.



5.连接数据库

db2inst1@Linux:/> db2 connect to QinDB

Database Connection Information

Database server = DB2/LINUXX8664 9.7.6
SQL authorization ID = DB2INST1
Local database alias = QINDB



6.给用户qinys授予DBA权限

db2inst1@Linux:/> db2 grant dbadm on database to user qinys
DB20000I The SQL command completed successfully.



7.为该用户创建scheme

db2inst1@Linux:/> db2 create schema qinysDM AUTHORIZATION qinys
DB20000I The SQL command completed successfully.



8.使用用户qinys登陆数据库

qinys@Linux:/> db2 connect to QinDB user qinys using qinys

Database Connection Information

Database server = DB2/LINUXX8664 9.7.6
SQL authorization ID = QINYS
Local database alias = QINDB



9.设置当前schema为qinysDM

db2 set current schema qinysDM



10.在该schema新建表tb

qinys@Linux:/> db2 "create table tb(id int)"
DB20000I The SQL command completed successfully.



11.db2look导出建表语句

qinys@Linux:~> db2look -d QinDB -e -u qinys -w qinys -t tb -o DDLfile.sql
-- The db2look utility will consider only the specified tables
-- Creating DDL for table(s)
-- Output is sent to file: DDLfile.sql


查看导出的脚本

【DB2】新建用户_建表

从上图我们可以清晰的看到,所建的表已经属于QINYSDM这个shema,说明shema已经设置成功。



作者:奔跑的金鱼