首先得开启db manager

[db2inst1@localhost ~]$ db2 start db manager

DB20000I  The START DATABASE MANAGER command completed successfully.

 

否则会有如下提示:

[db2inst1@localhost ~]$ db2 create database mydb

SQL1032N  No start database manager command was issued.  SQLSTATE=57019

 

开始创建数据库

[db2inst1@localhost ~]$ db2 create database mydb

DB20000I  The CREATE DATABASE command completed successfully.

注意以上命令没有指定数据库路径

可以用[db2inst1@localhost V10.1]$ db2 get dbm cfg查看数据库默认创建路径

我这边查到的是: Default database path                       (DFTDBPATH) = /home/db2inst1

 

若要显示所有已创建的数据库,执行:

[db2inst1@localhost ~]$ db2 list db directory

 

 System Database Directory

 

 Number of entries in the directory = 1

 

Database 1 entry:

 

 Database alias                       = MYDB

 Database name                        = MYDB

 Local database directory             = /home/db2inst1

 Database release level               = f.00

 Comment                              =

 Directory entry type                 = Indirect

 Catalog database partition number    = 0

 Alternate server hostname            =

 Alternate server port number         =

 

若要删除一个数据库可以用下面的命令

db2 drop database

 

 

 

 

选择Automatic storage(默认设置)允许DBA为数据库设置在创建所有表空间时可以使用

可以使用的存储路径。

 

创建表空间的时候出错,可以看到是没有连接到数据库

[db2inst1@localhost bin]$ db2  create tablespace test managed by automatic storage;

DB21034E  The command was processed as an SQL statement because it was not a

valid Command Line Processor command.  During SQL processing it returned:

SQL1024N  A database connection does not exist.  SQLSTATE=08003

 

用如下命令连接到MYDB数据库

[db2inst1@localhost bin]$ db2 connect to MYDB

 

   Database Connection Information

 

 Database server        = DB2/LINUXX8664 10.1.0

 SQL authorization ID   = DB2INST1

 Local database alias   = MYDB

成功创建表空间

[db2inst1@localhost bin]$ db2  create tablespace test managed by automatic storage;

DB20000I  The SQL command completed successfully.

 

 

db2 force application all      –强迫所有应用断开数据库连接

[db2inst1@localhost bin]$ db2 force application all

DB20000I  The FORCE APPLICATION command completed successfully.

DB21024I  This command is asynchronous and may not be effective immediately.

 

算开与数据库MYDB的连接

[db2inst1@localhost bin]$ db2 disconnect MYDB

DB20000I  The SQL DISCONNECT command completed successfully.

 

假如要创建一个同时支持XMLSQL的数据库,执行下面的命令:

[db2inst1@localhost bin]$ db2 create database xmldb using codeset UTF-8 territory us

DB20000I  The CREATE DATABASE command completed successfully.

 

 

[db2inst1@localhost bin]$ db2 connect to xmldb

 

   Database Connection Information

 

 Database server        = DB2/LINUXX8664 10.1.0

 SQL authorization ID   = DB2INST1

 Local database alias   = XMLDB

 

[db2inst1@localhost bin]$ db2 connect to MYDB

 

   Database Connection Information

 

 Database server        = DB2/LINUXX8664 10.1.0

 SQL authorization ID   = DB2INST1

 Local database alias   = MYDB

 

 

创建系统临时表空间

 

 




Related posts

coded by nessus
分享:  DeliciousGReader鲜果豆瓣CSDN网摘
Trackback

no comment untill now

Add your comment now

无觅相关文章插件