如何在Windows CMD里面用命令行 *** 作DB2数据库

如何在Windows CMD里面用命令行 *** 作DB2数据库,第1张

db2

cmd命令 *** 作

1、

打开命令行窗口

 

#db2cmd

2、

打开控制中心

 

#

db2cmd

db2cc

3、

打开命令编辑器

 db2cmd

db2ce

===== *** 作数据库命令=====

4、

启动数据库实例

 

#db2start

5、

停止数据库实例

 

#db2stop

 如果你不能停止数据库由于激活的连接,在运行db2stop前执行db2

force

application

all就可以了

/db2stop

force

我网上复制来的,可以稍微看下,其实DB2也有安装脚本的

安装DB2

DB2的安装可以算是再各个数据库里面最简单的了。除了sqlite。

下载安装包,解压

[root@Enterprise tmp]# tar xvf DB2_V82_PE_LNX_32_NLVtar

解开以后的文件都被放置在当前目录下的pe文件夹中。

开始安装:

[root@Enterprise tmp]# cd pe

[root@Enterprise pe]# ls

db2 db2_deinstall db2_install db2setup doc

[root@Enterprise pe]# /db2_install

Specify one or more of the following keywords,

separated by spaces, to install DB2 products

选择自己要安装的产品,输入名字后回车。等待安装完成。

我们现在需要做的是,对数据库的初始化工作。包括安装授权文件和创建一个实例并运行它。

首先,我们安装授权文件。

不安装授权文件的话,则是评估版,九十天后就要过期。授权文件,在安装包已经有了。我们用下面的命令安装它:

[root@Enterprise pe]# /opt/IBM/db2/V82/adm/db2licm -a /tmp/pe/db2/lic

ense/db2pelic

如果没有db2pelic 文件。可以去网上找找。

我们需要创建一个用户。

[root@Enterprise pe]# useradd db2inst1

[root@Enterprise pe]# passwd db2inst1

开始创建实例:

[root@Enterprise pe]# /opt/IBM/db2/V82/instance/db2icrt -u db2inst1 db2inst1

这样,我们就创建了一个实例db2ins1。

[root@Enterprise pe]# su db2inst1

[db2inst1@Enterprise pe]$ db2start

07/26/2007 16:45:10 0 0 SQL1063N DB2START processing was successful

SQL1063N DB2START processing was successful

这样我们数据库就启动成功。

[db2inst1@Enterprise pe]$ db2

(c) Copyright IBM Corporation 1993,2002

Command Line Processor for DB2 SDK 820

You can issue database manager commands and SQL statements from the command

prompt For example:

db2 => connect to sample

db2 => bind samplebnd

For general help, type:

For command help, type: command, where command can be

the first few keywords of a database manager command For example:

CATALOG DATABASE for help on the CATALOG DATABASE command

CATALOG for help on all of the CATALOG commands

To exit db2 interactive mode, type QUIT at the command prompt Outside

interactive mode, all commands must be prefixed with 'db2'

To list the current command option settings, type LIST COMMAND OPTIONS

For more detailed help, refer to the Online Reference Manual

db2 =>

创建一个最简单的数据库

db2 => create database testdb

DB20000I The CREATE DATABASE command completed successfully

查看本instance下有哪些database

db2 => list database directory

System Database Directory

Number of entries in the directory = 2

Database 1 entry:

Database alias = TESTDB

Database name = TESTDB

Local database directory = /home/db2inst1

Database release level = a00

Comment =

Directory entry type = Indirect

Catalog database partition number = 0

Alternate server hostname =

Alternate server port number =

Database 2 entry:

Database alias = OMNIDB

Database name = OMNIDB

Local database directory = /home/db2inst1/data

Database release level = a00

Comment =

Directory entry type = Indirect

Catalog database partition number = 0

Alternate server hostname =

Alternate server port number =

要使用 Navicat 连接 DB2 数据库,您需要执行以下步骤:

启动 Navicat,在主界面的左侧导航栏中单击“新建连接”。

在“连接类型”下拉菜单中选择“DB2”。

在“主机名/IP 地址”字段中输入 DB2 数据库所在服务器的 IP 地址或主机名。

在“端口”字段中输入 DB2 数据库的端口号。

在“数据库”字段中输入您要连接的 DB2 数据库的名称。

在“用户名”和“密码”字段中输入您的 DB2 数据库用户名和密码。

单击“测试连接”按钮,确保连接信息正确。

单击“保存”按钮保存连接设置,然后单击“连接”按钮连接到 DB2 数据库。

DB2数据库命令简介 1.启动数据库 DB2start 2.停止数据库 DB2stop DB2数据库在linux相关指令之3.连接数据库 DB2 connect to o_yd user DB2 using pwd 4.读数据库管理程序配置 DB2 get dbm cfg 5.写数据库管理程序配置 DB2 update dbm cfg using 参数名 参数值 6.读数据库的配置 DB2 connect to o_yd user DB2 using pwd DB2 get db cfg for o_yd 7.写数据库的配置 DB2 connect to o_yd user DB2 using pwd DB2 update db cfg for o_yd using 参数名 参数值 8.关闭所有应用连接 DB2 force application all DB2 force application ID1,ID2,,,Idn MODE ASYNC (DB2 list application for db o_yd show detail) 9.备份数据库 DB2 force application all DB2 backup db o_yd to d: (DB2 initialize tape on \tape0) (DB2 rewind tape on \tape0) DB2 backup db o_yd to \tape0 10.恢复数据库 DB2 restore db o_yd from d: to d: DB2 restore db o_yd from \tape0 to d: DB2数据库在linux相关指令之11.绑定存储过程 DB2 connect to o_yd user DB2 using pwd DB2 bind c:dfplusbnd 拷贝存储过程到服务器上的C:sqllibfunction目录中 12.整理表 DB2 connect to o_yd user DB2 using pwd DB2 reorg table ydd DB2 runstats on table ydd with distribution and indexes all 13.导出表数据 DB2 export to c:dftztxt of del select from dftz DB2 export to c:dftzixf of ixf select from dftz 14.导入表数据 import from c:123txt of del insert into ylbxczyxx DB2 import to c:dftztxt of del commitcount 5000 messages c:dftzmsg insert into dftz DB2 import to c:dftzixf of ixf commitcount 5000 messages c:dftzmsg insert into dftz DB2 import to c:dftzixf of ixf commitcount 5000 insert into dftz DB2 import to c:dftzixf of ixf commitcount 5000 insert_update into dftz DB2 import to c:dftzixf of ixf commitcount 5000 replace into dftz DB2 import to c:dftzixf of ixf commitcount 5000 create into dftz (仅IXF) DB2 import to c:dftzixf of ixf commitcount 5000 replace_create into dftz (仅IXF) 15.执行一个批处理文件 DB2 -tf 批处理文件名 (文件中每一条命令用 ;结束) 16.自动生成批处理文件 建文本文件:tempsql select 'runstats on table DB2' || tabname || ' with distribution and detailed indexes all;' from syscattables where tabschema='DB2' and type='T'; DB2 -tf tempsql>runstatssql 17.自动生成建表(视图)语句 在服务器上:C:sqllibmisc目录中 DB2 connect to o_yd user DB2 using pwd DB2look -d o_yd -u DB2 -e -p -c c:o_ydtxt DB2数据库在linux相关指令之18.其他命令 grant dbadm on database to user bb 19select from czyxx fetch first 1 rows only 20DB2look -d ylbx -u DB2admin -w -asd -a -e -o atxt21 显示当前用户所有表 list tables 22列出所有的系统表 list tables for system 23查看表结构 DB2 describe select from usertables (实习编辑:HJ)

一、安装前准备工作:

1、对于Linux系统,至ibm网站下载软件包

2、Linux内核设置:编辑/etc/sysctlconf文件

3、创建相应用户以及组:

4、创建相应目录用于存放db2的数据文件以及日志文件:

这里在根下面创建一个db2总目录,然后创建了一个15G大小的逻辑卷挂载/db2下面,然后在其下面创建相应的文件夹。

database目录存放数据库实例

db2log1存放db2的主日志文件

db2log2存放镜像日志文件

db2temp存放db2临时表空间

db2用户的家目录的位置

二、安装过程:

安装可以使用root用户安装也可以使用非root用户安装,这里就直接使用root用户安装了。

以root身份执行db2setup,会d出以下画面:

这里选择安装企业版,点击install new:

下一步之后,就出现创建用户的画面:

最后点击finish开始安装过程。

三、创建数据库:

如果在安装过程中,没有创建数据库,则后续可以使用db2cc命令创建数据库。这是一个基于图形界面的管理工具,使用起来也非常方便。执行db2cc后,会d出以下画面:

点击右侧的Create New Database,创建数据库:

指定数据库名称以及存放位置,选中Let DB2 manage my storage,下一步:

点击finish开始创建。默认db2会创建以下三个表空间:

(1)、catalog table space用于存放catalog表。

(2)、user table space存放所有表和索引数据。

(3)、temporary table space临时数据的存放位置。

创建完成后,会看到如下画面:

此时还没有连接到xzxjdb1上,点击右侧的connect进行连接。连接之后,会看到右侧多了好多信息:

使用命令行查看当前数据库中表空间信息:

四、DB2的简单管理:

1、查看表空间信息:

2、查看表信息:

3、查看当前实例下的所有数据库信息:

4、停止数据库:

5、启动数据库:

6、设置实例自动启动:

《Linux就该这么学》里有相关介绍,建议看看。

在创建数据库时要考虑几个因素,有几种创建数据库的方法。

可以使用从 Control Center 调用的 Create Database 向导,会引导用户分步创建数据库。要是了解实际的 Create Database 命令的话,还可以从 DB2 Command Window、Command Editor 或命令行直接发出命令。

在这个示例中,从 DB2 First Steps Launch 面板的 Create Database 向导:

1、启动 DB2 Control Center。点击 Start > All Programs > IBM DB2 > General Administration Tools 并选择 Control Center。当提示选择 Control Center 视图时,点击 OK 选择默认视图(Advanced)。

2、点击 All Databases(如图 5 所示),然后点击 Create New Database。Create Your Own Database 向导打开。

  5 从 Control Center 创建新数据库

3、在 Create Your Own Database 向导中,指定数据库名和数据库目录的位置。输入 HelloWld 作为数据库名。指定 C:\ 作为默认路径。输入 hwld 作为数据库别名。在 Comment 字段中输入任何描述性的注释。

4、选中 Enable Database for XML。XML 列只能在 UTF-8 代码集(Unicode)数据库中使用。所以要在数据库中使用 XML,就必须创建 Unicode 数据库。

5、不需要指定任何其他数据库选项,所以选择 Summary 面板,然后点击 Show Command 来查看创建这个数据库所用的 DB2 命令。

6、因为在这个数据库中启用了 XML,所以使用 CODESET UTF-8。点击 Close。如果想将命令保存到文件中,供以后参考或重用,那么点击 Save 而不是 Close。

7、在 Create New Database 窗口中,点击 Finish 并等待向导完成 *** 作。

在 DB2 创建数据库时,它还创建以下东西:

1、在指定的驱动器或路径上创建必要的数据库目录

2、创建一组默认的表空间,包括 SYSCAT、TEMPORARY 和 USER 表空间

3、在编目表空间中创建一组系统编目表和视图

4、创建数据库配置(DB CFG)文件并设置默认值

5、为数据库恢复日志文件创建空间并分配它

6、为数据库(如 CLI)和命令行处理器创建的几个应用程序

使用 DB2 Control Center 检查创建的数据库

在 Control Center 左边的面板中,找到并展开 All Systems 和 All Databases。看看是否能够找到刚才创建的 HELLOWLD 数据库。All Systems 提供了数据库对象视图,这些对象依次根据机器、实例和数据库进行分组。在这个机器上只有一个实例,DB2。All Databases 提供了这个机器上的所有数据库的快速查看。

6 查看新数据库

如果了解创建数据库所用的 DB2 命令,那么可以使用在前面的 Create New Database 向导窗口中保存的 CREATE DATABASE 命令并根据需要进行修改,然后从 DB2 命令行处理器发出 CREATE DATABASE 命令来创建数据库。

选择 Start > Run,输入 db2cmd 并按 Enter。打开 DB2 命令行处理器窗口。要想获得 create database 命令的帮助,可以在命令行窗口中输入 db2 create database。

输入 db2 CREATE DATABASE MYTESTDB ON C:。在命令成功完成之后,点击 Control Center 主菜单中的 Selected 并点击 Refresh。然后看看是否能够在 Control Center 中找到新的数据库 MYTESTDB。

在 DB2 命令窗口中输入命令 db2 LIST DATABASE DIRECTORY。应该会看到 HELLOWLD 和 MYTESTDB 数据库的数据库项。

以上就是关于如何在Windows CMD里面用命令行 *** 作DB2数据库全部的内容,包括:如何在Windows CMD里面用命令行 *** 作DB2数据库、怎么在linux上咱装DB2、navicat怎么连接db2数据库等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/9373877.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-27
下一篇2023-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存