Linux系统安装DB2数据库的详细步骤

Posted auspicious航

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux系统安装DB2数据库的详细步骤相关的知识,希望对你有一定的参考价值。

1、DB2数据库的安装

一、将DB2的安装介质上传至/home目录,并解压:

   tar –zxvf v9.5fp3_linuxx64_server.tar.gz

二、执行LANG=C

三、进入解压后的server目录(cd server/),执行./db2setup,步骤如下:

# cd /home

# tar -zxvf v9.7_linuxx64_server.tar.gz

# cd server/

# ./db2setup

 

 

请额外注意:这里选择 Do not create a DB2 instance。因为这样选择才能把db2软件装在本地。

输入主机名

安装完成。

2、在数据库服务器上创建用户和组

创建组db2iadm1(实例管理组),db2fgrp1(DB2 fencing管理组)和dasadm1(数据库管理员用户组),其中dasadm1组在安装数据库时已经创建,我们只需要创建db2iadm1和db2fgrp组:

# groupadd -g 206 db2iadm1

# groupadd -g 203 db2fgrp1

创建用户db2inst1(实例管理用户)、db2fenc1(DB2 fencing 管理用户)和dasusr1(数据库管理员用户),其中dasusr1用户在安装数据库时已经创建,我们只需要创建db2inst1和db2fenc用户

# useradd -g db2iadm1 -u 209 -d /home/db2inst1 db2inst1

# useradd -g db2fgrp1 -u 210 -d /home/db2fenc1 db2fenc1

3、在数据库服务器上更改目录权限

# mkdir /db2data

# chown -R db2inst1:db2iadm1 /home/db2inst1

# chown -R db2fenc1:db2fgrp1 /home/db2fenc1

# chown -R db2inst1:db2iadm1 /home

# chown -R db2inst1:db2iadm1 /db2data

4、在数据库服务器上创建实例db2inst1

# cd /opt/ibm/db2/V9.7/instance

    # ./db2icrt -u db2fenc1 db2inst1

DBI1070I  Program db2icrt completed successfully.

5、在数据库服务器上创建数据库(test)

# su - db2inst1

$ db2start

01/14/2019 09:48:57  0 0  SQL1063N  DB2START processing was successful.

$ db2 create database test using codeset UTF-8 territory zh_cn

DB20000I  The CREATE DATABASE command completed successfully.

修改数据库配置参数

$ db2 update db cfg for test using LOGFILSIZ 78600

$ db2 update db cfg for test using LOGPRIMARY 100

$ db2 update db cfg for test using LOGSECOND 30

修改完成后重启实例

$ db2stop force

2017-08-23 16:40:40    0  0  SQL1064N DB2STOPprocessing was successful.

SQL1064N DB2STOP processing was successful.

$ db2start

08/23/2017 16:40:44  0  0  SQL1063N DB2STARTprocessing was successful.

SQL1063N DB2START processing was successful.

检查相关参数

$ db2set –all

连接数据库

$ db2 connect to test

 Database Connection Information

 Database server        = DB2/LINUXX8664 9.7.0

 SQL authorization ID   = DB2INST1

 Local database alias   = TEST

在test数据库里创建test表并插入数据

$db2 "create  table test(NAME VARCHAR(20) NOT NULL , BIRTHDAY DATE)"

DB20000I  The SQL command completed successfully.

$ db2 "INSERT INTO test (NAME,BIRTHDAY) VALUES ('张三','2000-1-1')" 

DB20000I  The SQL command completed successfully.

$ db2 "INSERT INTO test (NAME,BIRTHDAY) VALUES ('李四','2000-1-1')" 

DB20000I  The SQL command completed successfully.

$ db2 "INSERT INTO test (NAME,BIRTHDAY) VALUES ('王五','2000-1-1')"

DB20000I  The SQL command completed successfully.

附:

1、开启数据库归档模式:

$ db2 update db cfg for test using logretain on

DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.

2、启用增量备份功能:

$ db2 update db cfg for test using trackmod on

DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.

3、创建备份目录并进行一次备份操作

$ cd /home/db2inst1

$ mkdir backup

$ db2 backup db test to /home/db2inst1/backup

Backup successful. The timestamp for this backup image is : 2019011409591

注意:如果原来是非归档模式, 手工开启归档模式之后,需要配置一定的归档清 理策略,保证归档可以被定期清理, 清理归档时最好能保留 3- 7天的归档,以保证归档HVR在一定延迟或者其他原因 没有及时抽取在线日志时,可以在归档中抽取数据变化。 如果用户部署了备份软件或者归档清理计划,也要对备份或清理计划 进行修改,保留3- 7天的归档。

设置完毕,大体情况如下:

$ db2 get db cfg for sample |grep -i log

Log retain for recovery status         = RECOVERY

First log archive method     (LOGARCHMETH1) = DISK:/archive/

4、打开 表的 补充日志

alter table table_name data capture changes include longvar columns。

linux系统安装rpm包数据库详细步骤

准备材料
1、rpm包
2、linux虚拟机

解压bundler安装包命令

tar -xvf mysql-8.0.27-1.el7.x86_64.rpm-bundle.tar。

解压包后生成文件

rpm -ivh mysql-community-common-8.0.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.27-1.el7.x

如果报错

[root@localhost mysql]# rpm -ivh mysql-community-libs-8.0.27-1.el7.x86_64.rpm 
warning: mysql-community-libs-8.0.27-1.el7.x86_64.rpm: Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	mariadb-libs is obsoleted by mysql-community-libs-8.0.27-1.el7.x86_64

执行以下命令,排查错误

[root@localhost mysql]# yum remove mysql-libs

然后再重新安装即可。

[root@localhost mysql]# rpm -qa | grep -i mysql
mysql-community-server-8.0.27-1.el7.x86_64
mysql-community-client-plugins-8.0.27-1.el7.x86_64
mysql-community-libs-8.0.27-1.el7.x86_64
mysql-community-client-8.0.27-1.el7.x86_64
mysql-community-common-8.0.27-1.el7.x86_64

查询mysql状态

[root@localhost mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
[root@localhost mysql]# systemctl start mysqld

开启mysql

root@localhost mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-07-19 00:20:34 PDT; 2s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 6221 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 6302 (mysqld)
   Status: "Server is operational"
    Tasks: 38
   CGroup: /system.slice/mysqld.service
           └─6302 /usr/sbin/mysqld

Jul 19 00:20:21 localhost.localdomain systemd[1]: Starting MySQL Server...
Jul 19 00:20:34 localhost.localdomain systemd[1]: Started MySQL Server.

查找临时密码

[root@localhost mysql]# grep "temporary password" /var/log/mysqld.log
2022-07-19T07:20:26.212621Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: EhnFd0aysV=K

登录并且更改临时密码

[root@localhost mysql]#  mysql -uroot -p
Enter password: 

mysql> alter user 'root'@'localhost' identified by '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> alter user 'root'@'localhost' identified by '123.aA456';
Query OK, 0 rows affected (0.07 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host, user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
4 rows in set (0.00 sec)

mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select host, user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| %         | root             |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
+-----------+------------------+
4 rows in set (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

以上是关于Linux系统安装DB2数据库的详细步骤的主要内容,如果未能解决你的问题,请参考以下文章

linux怎么连接linux下的db2

linux怎么连接linux下的db2

linux系统下 重启db2数据库

linux下安装配置JDK,详细步骤图文

Linux源码安装jdk1.8详细步骤

linux安装mysql详细步骤