background
It is very troublesome to install oracle in Linux, and I believe everyone will encounter various pits. In order to install it once, it is also convenient to directly export the image for transplantation on various platforms in the future, so I choose to install Oracle with docker.
The download speed is very slow using the official image, so we can use the Ali image.
pull image
Pull the oracle_11g image
Pull the oracle image (oracle 11.0.2 64bit enterprise version instance name: helowin)
Oracle is mainly installed on the basis of Docker. Pay attention to space and memory in the installation environment. Oracle is a very large piece of software.
The minimum configuration should be more than 2G, and the hard disk should be more than 30G, because the image has a size of 6.8G.
Log in to the Alibaba container image service platform, find the image center --> image search, enter the corresponding image name to find a suitable image.
It is recommended to use Netease mirror or Ali mirror website here to oracle 11.0.2 64bit enterprise version
Instance name: helowin is an example for installation details.
docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
run container
2.1 The default way to start the container
docker run -d --name oracle11g -p 1521:1521 --restart=always registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
或
docker run -d -it -p 1521:1521 \
--name oracle11g \
--restart=always registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
2.2 The way of persistent startup
docker run -d -it -p 1521:1521 --name oracle11g --restart=always --mount source=oracle_vol,target=/home/oracle/app/oracle/oradata registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
或
docker run -d -it -p 1521:1521 \
--name oracle11g \
--restart=always \
--mount source=oracle_vol,target=/home/oracle/app/oracle/oradata registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
Generally, the default startup method is enough. If the data needs to be saved locally, the persistent method is used.
--mount means to mount the path on the Host into the container.
source=oracle_vol is the persistent volume of the Host. If it is not created in advance, it will be created automatically. You can pass
target=/home/oracle/app/oracle/oradata: your own Linux home directory
docker volume inspect oracle_vol
View the specific location of the volume, target is the path in the container
View container startup status
docker ps | grep oracle11g
Enter the oracle11g container for configuration
docker exec -it oracle11g /bin/bash
Switch to the root user for configuration:
Switch root user: su root
Enter password: helowin ##You can use the passwd command to change your own password
Edit the profile file to configure the ORACLE environment variable:
vi /etc/profile
At the end of the document, add the following:
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2
export ORACLE_SID=helowin
export PATH=$ORACLE_HOME/bin:$PATH
After saving, load the environment variable and it will take effect immediately:
source /etc/profile
Create a soft link:
Function: You can use the oracle command directly without entering the bin directory to execute the corresponding command.
ln -s $ORACLE_HOME/bin/sqlplus /usr/bin
Switch to the oracle user:
su - oracle
登录sqlplus并修改sys、system用户密码:
sqlplus /nolog # 登录oracle
conn /as sysdba # 连接,需要进行操作系统验证,才可进行连接登录
alter user system identified by system; # 修改system用户账号密码system
alter user sys identified by sys; # 修改sys用户账号密码sys
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED; # 修改密码规则策略为密码永不过期
exit; # 退出
supplementary order
补充命令
登录sqlplus并修改sys、system用户密码: 需要注意的是再oracle用户下操作
sqlplus /nolog # 登录
conn /as sysdba # 连接
create user test identified by test; #创建内部管理员账号密码;
grant connect,resource,dba to yan_test; #将dba权限授权给内部管理员账号和密码;
alter system set processes=1000 scope=spfile; #修改数据库最大连接数据;
修改以上信息后,需要重新启动数据库
shutdown immediate; #关闭数据库
startup; #启动数据库
SQL> select instance from v$thread; #查看数据库sid(实例名)
clear SCR 或clear screen或clea scre #sqlplus清屏命令
创建表空间
create tablespace pts datafile '/home/oracle/app/oracle/oradata/helowin/pts.dbf' size 100m autoextend on next 10m
删除表空间
drop tablespace PTS;
查看所有表空间
select tablespace_name from dba_tablespaces;
创建用户
create user PTS identified by PTS default tablespace PTS;
删除用户
drop user pts cascade;
为sys用户添加sysdba权限
SQL> grant sysdba to sys;
查看哪些用户被授予DBA权限
select * from dba_role_privs where granted_role='DBA';
查看数据库编码
SQL> select userenv('language') from dual;
View database permissions and users
SQL> show parameter password #查看数据库权限
SQL> select * from v$pwfile_users; #查看用户
Check the oracle instance status:
lsnrctl status -查看一下oracle实例状态:
listen command
$ lsnrctl stop listener -停止名为listener的监听服务
$ lsnrctl start listener -启动名为listener的监听服务
$ lsnrctl reload listener -重新加载名为listener的监听服务
View environment variables
cat /home/oracle/.bash_profile
看到此ORACLE_SID=helowin表示数据库的实例名称
navicate连接