8

Linux下部署Oracle 11g(详细文档)

 3 years ago
source link: https://my.oschina.net/u/4562085/blog/4817111
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Linux下部署Oracle 11g(详细文档)

一、环境准备

有需要安装时的软件或安装中遇到的一些问题,请私信解决!

1.linux.x64_11gR2_database_1of2.zip

linux.x64_11gR2_database_2of2.zip (下载地址

2.还可能会用到Xmanager中的Xstart

二、 安装前准备

1、创建oracle数据库的系统用户和用户组

admin \@localhost \~]\$ su root
Password:

[root\@localhost admin]\# groupadd oinstall   \#创建用户组oinstall

[root\@localhost admin]\# groupadd dba      \#创建用户组dba

[root\@localhost admin]\# useradd -g oinstall -G dba -m oracle  
   \#创建oracle用户,并加入到oinstall和dba用户组\
   
[root\@localhost admin]\# passwd oracle     \#设置用户oracle的登陆密码
Changing password for user oracle.
New password: BAD PASSWORD: The password is shorter than 8 characters Retype new
password:                                    \#确认密码
passwd: all authentication tokens updated successfully.

[root\@localhost admin]\# id oracle           \#查看新建的oracle用户
uid=1001(oracle) gid=1002(dba) groups=1002(dba)

*:-g:指定用户所属的群组 -G:指定用户所属的附加群组 -m:自动建立用户的登入目录

2、创建oracle数据库安装目录

[root\@localhost admin]\# mkdir -p /data/oracle         \#安装目录

[root\@localhost admin]\# mkdir -p /data/oraInventory      \#配置文件目录

[root\@localhost admin]\# mkdir -p /data/orapackage     \#软件包解压目录

[root\@localhost admin]\# cd /usr

[root\@localhost usr]\# ls 
orapackage oracle oraInventory ...
[root\@localhost usr]\# chown -R oracle:oinstall /data/oracle 
  \#设置目录所有者为oinstall用户组的oracle用户
[root\@localhost usr]\# chown -R oracle:oinstall /data/oraInventory

[root\@localhost usr]\# chown -R oracle:oinstall /data/orapackage

3、修改OS系统标识

oracle默认不支持CentOS系统安装, 修改文件 /etc/RedHat-release 内容为RedHat-7

[root\@localhost admin]\#vi /etc/redhat-release   \#修改文件名称
redhat-7

4.安装oracle数据库所需要的软件包

可参考:https://docs.oracle.com/cd/E11882_01/install.112/e47689/pre_install.htm#BABCFJFG 安装所需安装包

[root\@localhost admin]\# yum -y install binutils compat-libcap1
compat-libstdc++-33 compat-libstdc++-33\*i686 compat-libstdc++-33\*.devel
compat-libstdc++-33 compat-libstdc++-33\*.devel gcc gcc-c++ glibc glibc\*.i686
glibc-devel glibc-devel\*.i686 ksh libaio libaio\*.i686 libaio-devel
libaio-devel\*.devel libgcc libgcc\*.i686 libstdc++ libstdc++\*.i686
libstdc++-devel libstdc++-devel\*.devel libXi libXi\*.i686 libXtst
libXtst\*.i686 make sysstat unixODBC unixODBC\*.i686 unixODBC-devel
unixODBC-devel\*.i686

检测是否31个包都有安装

rpm -q binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel
ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make
sysstat unixODBC unixODBC-devel

5、关闭防火墙

CentOS 7默认使用的是firewall作为防火墙

[root\@localhost admin]\# systemctl status firewalld.service         \#查看防火墙状态
● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded
(/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2016-04-07 18:54:29 PDT; 2h 20min ago

[root\@localhost admin]\# systemctl stop firewalld.service          \#关闭防火墙

[root\@localhost admin]\# systemctl status firewalld.service       \#再次查看防火墙状态 
● firewalld.service - firewalld -dynamic firewall daemon Loaded: loaded
(/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Thu 2016-04-07 21:15:34 PDT; 9s ago

[root\@localhost admin]\# systemctl disable firewalld.service        \#关闭开机自动启动

6、关闭selinux(需重启生效)

[root\@localhost /]\# vi /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded. SELINUX=disabled    \#此处修改为disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are
protected.
# mls - Multi Level Security protection. SELINUXTYPE=targeted

7、修改内核参数

[root\@localhost admin]\# vi /etc/sysctl.conf

# System default settings live in /usr/lib/sysctl.d/00-system.conf.
# To override those settings, enter new settings here, or in an
/etc/sysctl.d/\<name\>.conf file
# For more information, see sysctl.conf(5) and sysctl.d(5).
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.rp_filter = 1
fs.file-max = 6815744    \#设置一个进程可以打开的最大打开文件数
fs.aio-max-nr = 1048576    \#限制未完成的并发请求,避免I/O系统故障
kernel.shmall = 2097152
    #共享内存的总量,应不小于shmmax/page_size缺省值就是2097152
kernel.shmmax = 2147483648    \#最大共享内存的段大小,不小于物理内存的一半
kernel.shmmni = 4096      \#整个系统共享内存端的最大数
kernel.sem = 250 32000 100 128     \#设置的信号量
net.ipv4.ip_local_port_range = 9000 65500    \#可使用的IPv4端口范围
net.core.rmem_default = 262144     \#默认接收缓冲区大小
net.core.rmem_max= 4194304     \#接收缓冲区最大值
net.core.wmem_default= 262144    \#默认的发送缓冲区大小
net.core.wmem_max= 1048576     \#发送缓冲区最大值

使配置参数生效
[root\@localhost admin]\# sysctl –p

8、设置用户限制,提高软件运行性能

[root\@localhost admin]\# vi /etc/security/limits.conf

#@student - maxlogins 4
.................
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536  
oracle soft stack 10240  
oracle hard stack 32768

# End of file

10、配置用户的环境变量

[root\@localhost /]\# vi /home/oracle/.bash_profile (看仔细,很重要)
...........

export PATH

export ORACLE_BASE=/data/oracle      \#oracl安装目录

export ORACLE_HOME=\$ORACLE_BASE/product/11.2.0/db_1   \#oracle路径

export ORACLE_SID=orcl     \#oracle启动数据库实例名

export ORACLE_TERM=xterm    \#xterm窗口模式安装

export PATH=\$ORACLE_HOME/bin:/usr/sbin:\$PATH     \#添加系统环境变量

export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib   \#添加系统环境变量

export LANG=C    \#防止安装过程出现乱码

export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK   \#设置Oracle客户端字符集,

必须与Oracle客户端安装时设置的字符集保持一致。有的是设为AL32UTF8,根据需要自行设定。

获取安装包文件的方式,可通过ftp服务器,也可通过wget下载到指定目录,解压方式如下

在oracle用户中上传1gR2_database_1of2.ziplinux.x64_11gR2_database_2of2.zip安装包上传到/usr/local/src

[oracle\@localhost /]\$ cd /usr/local/src  \#进入/usr/local/src目录

[oracle\@localhost src]\$ ls

linux.x64_11gR2_database_1of2.zip  linux.x64_11gR2_database_2of2.zip

[oracle\@localhost src]\$ unzip linux.x64_11gR2_database_1of2.zip –d
/data/database/                      \#解压到data目录下

(省略...)

[oracle\@localhost src]\$ unzip linux.x64_11gR2_database_2of2.zip -d
/data/database/              \#解压到data目录下

(省略...)

使配置生效

[root\@localhost admin]\# source /home/oracle/.bash_profile

三、oracle安装

[oracle\@localhost \~]\$ cd /data/database/

[oracle\@localhost database]\$ ls

doc install response rpm runInstaller sshsetup stage welcome.html
[oracle\@localhost database]\$ ./runInstaller

安装问题:

  1. 安装Oracle数据库软件,提示“检查监视器”未通过

检查临时空间: 必须大于 120 MB。 实际为 36939 MB 通过

检查交换空间: 必须大于 150 MB。 实际为 8047 MB 通过

检查监视器: 监视器配置至少必须显示 256 种颜色

\>\>\> 无法使用命令 /usr/bin/xdpyinfo 自动检查显示器颜色。请检查是否设置了

DISPLAY 变量。 未通过 <<<<

解决方法:根据报错信息,首先想到的是配置DISPLAY变量(一般配置一下就可以解决)

[root\@db130 \~]\# yum install -y xdpyinfo

[root\@db130 \~]\# xhost +

access control disabled, clients can connect from any host

[root\@db130 \~]\# su - oracle

[oracle\@db130 \~]\$ export DISPLAY=:0.0

[oracle\@db130 \~]\$ cd /data/database/database/

[oracle\@db130 database]\$ ./runInstaller

正在启动 Oracle Universal Installer...

  1. 过程弹框界面是一个白色竖线一般,整个界面无法点击next按钮

解决办法这里推荐使用Xmanager工具中的Xstart

保持CentOS联网状态,以root用户登录,执行命令:yum install -y xterm

安装完毕后,启动Xstart,输入主机IP并用oracle用户登录,

输入命令:/usr/bin/xterm -ls -display $DISPLAY

进入安装界面

(1)如下图所示,去掉“I wish receive security via My Oracle Support”的勾选,单击“next”,选“yes”继续。

(2)选中“Create and configure a database”,点击“next”

第一项为企业级应用

第二项只安装数据库

第三项为升级现有数据库

(3)选中“DesktopClass”,点击“next”

第一项为桌面类:一般适用于台式机和笔记本,包含最小数据库和最低配置要求,安装时只有基本选项。

第二项为服务类:适用于服务器,例如,它会向您提供数据中心和用于支持企业级的应用程序。

4)这里如果安装前准备按照文档操作的话,这里只需填写passwrod即可(无视警告),点击“next”

(5)之后的配置一般都选择默认,当流转到这个界面时,选中Character sets选项,

修改字符集为UTF-8后继续“next”

(6)之后配置继续按照默认即可,当流转到这个界面时,可以为所有用户设置密码,我设置的oracle,点击“next

(6)流转到这个页面,如果之前安装依赖包会有下面图中包提示失败,一个一个检查package,在准备阶段中漏掉的,此处再安装,有些系统报错是因为现有的包的版本比检测要高,最后忽略即可。(点击Check_Again 多检查几次,根据错提示进行操作)

(7)当安装进度达到68%时,会出现如上图所示报错(根据报错打开该文件)

查找安装目录下该文件:/usr/oracle/product/11.2.0/db_1/ctx/lib/ins_ctx.mk

[admin \@localhost \~]\$ su root
Password:
[root\@localhost admin]\# vim /usr/oracle/product/11.2.0/db_1/ctx/lib/ins_ctx.mk
修改如下文件内容(11行左右)
ctxhx: \$(CTXHXOBJ)
\$(LINK_CTXHX) \$(CTXHXOBJ) \$(INSO_LINK)
修改为:
ctxhx: \$(CTXHXOBJ)
\-static \$(LINK_CTXHX) \$(CTXHXOBJ)\$(INSO_LINK) /usr/lib64/libc.a

保存(:wq)后,点击Retry继续安装

若还报错 打开此安装目录下文件:/usr/oracle/product/11.2.0/db_1/sysman/lib/ins_emagent.mk

修改如下内容(190行左右)
\$(MK_EMAGENT_NMECTL)
修改为
\$(MK_EMAGENT_NMECTL) -lnnz11

打开控制端,以root权限执行所示两个脚本

[root\@localhost /]\# sh /usr/oraInventory/orainstRoot.sh
[root\@localhost /]\# sh /usr/oracle/product/11.2.0/db_1/root.sh
此处输入红色部分的路径回车:
Enter the full pathname of the local bin directory: [/usr/local/bin]:
Copying dbhome to /usr/local/bin ...
Copying oraenv to /usr/local/bin ...
Copying coraenv to /usr/local/bin ...

4、创建Oracle监听

[oracle\@localhost \~]\$ netca

选择监听器协议,默认TCP,点击Next 配置监听端口,默认1521,点击Next 配置完成,提示是否增加另外的监听器,选择No,点击Next 点击Finish结束配置程序,命令行界面会提示配置的信息并将新的监听器启动

监听器的启动和停止

lsnrctl start LISTENER #启动名为LISTENER的监听器 lsnrctl stop LISTENER #关闭名为LISTENER的监听器

查看监听器运行状态

lsnrctl status LISTENER #查看名为LISTENER的监听器的运行状态

5、安装oracle数据库实例

[oracle\@localhost \~]\$ dbca

1)、在/etc/fstab中明确指定/dev/shm的挂载sizes大小参数**

查看/dev/shm的大小

[oracle\@localhost \~]\$ df –h /dev/shm

Filesystem Size Used Avail Use% Mounted on

tmpfs 1.9G 29M 1.8G 2% /dev/shm

可以看到/dev/shm的大小为1.9G,设置为70%的时候所需空间的大小为2582M,已经超出其最大空间。/dev/shm默认为物理内存大小的一半,根据需要我将其设为3G,以root权限执行以下命令:

[root\@localhost oracle]\# vi /etc/fstab

tmpfs /dev/shm tmpfs defaults 0 0

修改为

tmpfs /dev/shm tmpfs defaults,size=3G 0 0

如果没有就直接添加上去,保存退出(:wq)

2)、将/dev/shm重新挂载

[root\@localhost oracle]\# mount -o remount /dev/shm

[root\@localhost oracle]\# df –h /dev/shm

Filesystem Size Used Avail Use% Mounted on

tmpfs 3.0G 25M 3.0G 1% /dev/shm

此种方式是永久更改/dev/shm 的空间大小,如果只要临时更改(重启无效),执行如下命令:

[oracle\@localhost \~]\$ sudo mount -o size=3G -o remount /dev/shm

设置字符集,选择与安装Oracle时的设置相同的字符集,ZHS16GBK。如果Oracle用的字符集为AL32UTF8,就选择AL32UTF8。当然,如果这里字符集选错了,安装好了也是可以修改的,只是稍有麻烦。

设置连接类型,共享内存或者独享内存,也可以默认,点击Next

选择Generate Database Creation Scripts(生成数据库创建脚本),可以为手工建库脚本提供参考

点击Finish,完成创建

启动监听:lsnrctl start #必须将监听启动,如果之前防火墙没关,还需要关闭防火墙。

输入:sqlplus /nolog

输入:conn sys/sys[@orcl](https://my.oschina.net/u/3674287) as sysdba

其中,orcl是实例名,sys是它的密码。如果出现下图所示的“Connected.”则连接成功,说明数据库建立成功(这里是在CentOS终端上使用的)。

输入:sqlplus scott/[email protected]:1521/orcl ,回车(查询ip,使用ifconfig 命令)

查询当前用户:show user;

查询用户下有几张表:select * from tab;

查询表字段:desc emp ; #emp是表名

查询表数据:select * from emp;

退出SQL命令模式exit;

6、创建表空间和用户授权

1)、连接数据库

[oracle\@localhost \~]\$ sqlplus /nolog

SQL\*Plus: Release 11.2.0.1.0 Production on Fri Jan 19 10:23:13 2018

Copyright (c) 1982, 2009, Oracle. All rights reserved.

SQL\> conn / as sysdba

Connected.

SQL\>

2)、创建数据表空间

SQL\> CREATE TABLESPACE ALS LOGGING DATAFILE '/usr/oracle/oradata/orcl/ALS.DBF'
SIZE 50M AUTOEXTEND ON NEXT 50M MAXSIZE 20480M EXTENT MANAGEMENT LOCAL;

CREATE TABLESPACE 表空间名 LOGGING DATAFILE '存放路径' SIZE 50M AUTOEXTEND ON NEXT 50M MAXSIZE 20480M EXTENT MANAGEMENT LOCAL;

3)、创建用户并指定表空间

SQL\> CREATE USER sa IDENTIFIED BY kcsm111 DEFAULT TABLESPACE ALS;

CREATE USER 用户名 IDENTIFIED BY 密码 DEFAULT TABLESPACE 表空间名;

4)、给用户授予权限

SQL\>grant connect,resource,dba to sa;

grant connect,resource,dba to 用户名;

5)、删除表空间

SQL\> drop tablespace ALS including contents and datafiles cascade constraints;

drop tablespace 表空间名 including contents and datafiles cascade constraints;

including contents 删除表空间中的内容,如果删除表空间之前表空间中有内容,而未加此参数,表空间无法删除。

including datafiles 删除表空间中的数据文件

cascade constraints 同时删除表空间中表的外键参照

至此所有安装完成

四、 设置数据库自启动 方法一: 1、安装好Oracle数据库后: 执行 dbstart和dbshut

[oracle\@localhost \~]\$ dbstart

ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener

Usage: /usr/oracle/product/11.2.0/db_1/bin/dbstart ORACLE_HOME

错误原因:dbstart和dbshut脚本文件中ORACLE_HOME_LISTNER的设置有问题

[oracle\@localhost \~]\$ vim \$ORACLE_HOME/bin/dbstart

[oracle\@localhost \~]\$ vim \$ORACLE_HOME/bin/dbshut

分别打开两个文件修改(50行左右)

ORACLE_HOME_LISTNER=\$1

修改为:

ORACLE_HOME_LISTNER=\$ORACLE_HOME

修改后保存退出,问题解决

2、Linux启动时自动启动Oracle监听和实例

第一步:修改/etc/oratab文件

[oracle\@localhost \~]\$ vim /etc/oratab

找到: orcl:/usr/oracle/product/11.2.0/db_1:N

修改为: orcl:/usr/oracle/product/11.2.0/db_1:Y

(这个路径跟安装路径有关,$ORACLE_SID:$ORACLE_HOME:<N|Y>)

第二步:把lsnrctl start和dbstart添加到rc.local文件中:

root权限执行

[root\@localhost oracle]\# vim /etc/rc.d/rc.local

添加:

su - oracle -lc "/usr/oracle/product/11.2.0/db_1/bin/lsnrctl start"

su - oracle -lc "/usr/oracle/product/11.2.0/db_1/bin/dbstart"

第一行为开机启动数据库监听服务,第二行为开机启动数据库。(路径跟安装路径相关)。

注意:CentOs7中/etc/rc.d/rc.local不会开机执行,需添加执行权限。

查看/etc/rc.d/rc.local的权限

[root\@localhost oracle]\# ll /etc/rc.d/rc.local

添加执行权限

[root\@localhost oracle]\# chmod +x /etc/rc.d/rc.local

3、重启电脑后查看是否自启动成功

查看监听是否自启动成功

[oracle\@localhost \~]\$ lsnrctl status LISTENER

查看Oracle服务状态

[oracle\@localhost \~]\$ ps –ef \| grep oracle

4、oracle的启动或关闭管理

[root\@localhost oracle]\# dbstart    \#启动

[root\@localhost oracle]\# dbshut

1、修改/etc/oratab文件

root权限执行

[root\@localhost oracle]\# vim /etc/oratab

找到: orcl:/usr/oracle/product/11.2.0/db_1:N

修改为: orcl:/usr/oracle/product/11.2.0/db_1:Y

(这个路径跟安装路径有关,$ORACLE_SID:$ORACLE_HOME:<N|Y>)

2、新建Oracle服务自启动脚本

[root\@localhost oracle]\# vim /etc/init.d/oracle

将以下脚本复制到文件中,保存退出(:wq)

\#!/bin/sh

\# chkconfig: 2345 61 61

\# description: Oracle 11g R2 AutoRun Servimces

\# /etc/init.d/oracle

\#

\# Run-level Startup script for the Oracle Instance, Listener, and

\# Web Interface

export ORACLE_BASE=/usr/oracle    \#oracle安装位置

export ORACLE_HOME=\$ORACLE_BASE/product/11.2.0/db_1   \#Oracle安装路径

export ORACLE_SID=orcl

export PATH=\$PATH:\$ORACLE_HOME/bin

ORA_OWNR="oracle"
\# if the executables do not exist -- display error
if [ ! -f \$ORACLE_HOME/bin/dbstart -o ! -d \$ORACLE_HOME ]
then
echo "Oracle startup: cannot start"
exit 1
fi
\# depending on parameter -- startup, shutdown, restart
\# of the instance and listener or usage display
case "\$1" in
start)
\# Oracle listener and instance startup
su \$ORA_OWNR -lc \$ORACLE_HOME/bin/dbstart
echo "Oracle Start Succesful!OK."
;;
stop)

\# Oracle listener and instance shutdown
su \$ORA_OWNR -lc \$ORACLE_HOME/bin/dbshut
echo "Oracle Stop Succesful!OK."
;;
reload\|restart)
\$0 stop
\$0 start
;;
\*)
echo \$"Usage: \`basename \$0\` {start\|stop\|reload\|reload}"
exit 1
esac
exit 0

3、检查脚本能否执行

[root\@localhost oracle]\# /etc/init.d/oracle start   \#启动oracle脚本

[root\@localhost oracle]\# /etc/init.d/oracle stop    \#关闭oracle脚本

[root\@localhost oracle]\# /etc/init.d/oracle restart  \#重启oracle脚本

4、添加执行权限并建立链接

更改oracle脚本的执行权限

[root\@localhost oracle]\# chmod a+x /etc/init.d/oracle

将启动脚本添加到系统服务并设置自启动

[root\@localhost oracle]\# chkconfig --add oracle

修改服务运行等级(虽然脚本里写过,但还是重新设置一下),可以自行设置oracle脚本的运行级别

[root\@localhost oracle]\# chkconfig --level 2345 oracle on

说明:设置oracle脚本在运行级别为2、3、4、5时,都是on(开启)状态,off为关闭

查看oracle自动启动设置

[root\@localhost oracle]\# chkconfig –list oracle

Oracle 0:off 1:off 2:on 3:on 4:on 5:on 6:off

*等级0表示:表示关机
等级1表示:单用户模式
等级2表示:无网络连接的多用户命令行模式
等级3表示:有网络连接的多用户命令行模式
等级4表示:不可用
等级5表示:带图形界面的多用户模式
等级6表示:重新启动*

手动创建符号链接文件(执行效果和执行chkconfig --add oracle是一样,作为知识笔记记录,可以不执行)

[root\@localhost oracle]\# ln –s /etc/rc.d/init.d/oracle /etc/rc0.d/K61oracle

[root\@localhost oracle]\# ln –s /etc/rc.d/init.d/oracle /etc/rc1.d/K61oracle

[root\@localhost oracle]\# ln –s /etc/rc.d/init.d/oracle /etc/rc2.d/S61oracle

[root\@localhost oracle]\# ln –s /etc/rc.d/init.d/oracle /etc/rc3.d/S61oracle

[root\@localhost oracle]\# ln –s /etc/rc.d/init.d/oracle /etc/rc4.d/S61oracle

[root\@localhost oracle]\# ln –s /etc/rc.d/init.d/oracle /etc/rc5.d/S61oracle

[root\@localhost oracle]\# ln –s /etc/rc.d/init.d/oracle /etc/rc6.d/K61oracle

5、oracle的启动或关闭管理

[root\@localhost oracle]\# service oracle start    ##//启动

[root\@localhost oracle]\# service oracle stop     ##//停止

[root\@localhost oracle]\# service oracle restart   ##//重启

五、 数据库字符集修改

注意事项:修改字符集前先将数据库进行备份

此处演示将ZHS16GBK字符集修改为AL32UTF8

1、修改server端字符集

登录sqlpus查看字符集设置

[oracle\@localhost \~]\$ sqlplus /nolog

SQL\*Plus: Release 11.2.0.1.0 Production on Wed Jan 24 13:55:51 2018

Copyright (c) 1982, 2009, Oracle. All rights reserved.

SQL\> conn /as sysdba

Connected to an idle instance.

数据库未启动,先启动数据库。最好将数据库设未开机启动

SQL\> startup

SQL\> conn /as sysdba

Connected. \#连接成功

SQL\> select userenv('language') from dual; \#server端字符集查询

USERENV('LANGUAGE')

\----------------------------------------------------

AMERICAN_AMERICA.ZHS16GBK

依次执行如下命令

SQL\>SHUTDOWN IMMEDIATE;

SQL\>STARTUP MOUNT;

SQL\>ALTER SYSTEM ENABLE RESTRICTED SESSION;

SQL\>ALTER SYSTEM SET JOB_QUEUE_PROCESSES=**0**;

SQL\>ALTER SYSTEM SET AQ_TM_PROCESSES=**0**;

SQL\>ALTER DATABASE OPEN;

SQL\>ALTER DATABASE CHARACTER SET INTERNAL_USE AL32UTF8;

SQL\>SHUTDOWN IMMEDIATE;

SQL\>STARTUP;

SQL\> select userenv('language') from dual;

USERENV('LANGUAGE')

AMERICAN_AMERICA.AL32UTF8

SQL\>

2、修改client端字符集

查看系统环境变量设置的字符集(client端字符集)


[oracle\@localhost \~]\$ cat /home/oracle/.bash_profile

...

PATH=\$PATH:\$HOME/.local/bin:\$HOME/bin

export PATH

export ORACLE_BASE=/usr/oracle

export ORACLE_HOME=\$ORACLE_BASE/product/**11.2**.**0**/db_1

export ORACLE_SID=orcl

export ORACLE_TERM=xterm

export PATH=\$ORACLE_HOME/bin:/usr/sbin:\$PATH

export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib

export LANG=C

export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK  \#客户端字符集

[外链图片转存中...(img-iD0JQrjM-1576131393379)]

进入编辑界面,将ZHS16GBK改为AL32UTF8,保存退出

[oracle\@localhost \~]\$ vim /home/oracle/.bash_profile

那么使配置生效

[oracle\@localhost \~]\$ source /home/oracle/.bash_profile

如果创建用户名密码登陆不上,仔细查看环境变量(vim /home/oracle/.bash_profile)是否正确,可能原因找不到SID,执行:

[oracle\@localhost \~]\$ export ORACLE_SID=orcl

下面基本就完成部署了,如果有补充或修改还请留言哦!!///////


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK