docker安装Oracle数据库
一、下载Oracle安装包
https://download.oracle.com/otn/linux/oracle11g/R2/linux.x64_11gR2_database_1of2.zip
https://download.oracle.com/otn/linux/oracle11g/R2/linux.x64_11gR2_database_2of2.zip
链接: https://pan.baidu.com/s/1MfYw7PoPekl7C0vJ6Z-PAg 提取码: bumr
下载完后,两个压缩包解压到同一个文件夹内,例如:/home/user/oracle_installer
二、拉取docker镜像
docker pull jaspeen/oracle-11g
这个镜像只是提供了安装Oracle的环境和脚本,并没有安装好Oracle
三、启动镜像,安装Oracle
/home/user/oracle_installer为Oracle安装包解压后的所在目录
docker run --privileged --name oracle11g -p 1521:1521 -v /home/user/oracle_installer:/install jaspeen/oracle-11g
privileged 是给这个容器里面脚本权限,安装oracle可能需要操作需要root权限的文件或目录
这个安装过程会比较漫长,取决于你机器的配置,当看到日志里有 100% complete 打印,表示oracle安装成功了
四、设置Oracle
scott用户是系统默认给的一个用户,我们可以用它来测试数据库,但是默认情况下它是锁定的
-
连接到容器中:
docker exec -it oracle11g /bin/bash -
切换到oracle用户登录:
su - oracle -
使用管理员登录oracle:
sqlplus / as sysdba -
解锁scott用户:
alter user scott account unlock; commit; -
当然你也可以创建自己的用户:
create user myuser identified by "123" default tablespace USERS temporary tablespace TEMP profile DEFAULT; grant connect to myuser; grant ctxapp to myuser; grant resource to myuser; -
修改用户密码:
-- 查看用户列表 select username from dba_users; -- alter user 用户名 identified by 新密码; alter user apps identified by 123456;
五、修改字符集
-
查询当前使用的字符集
select userenv('language') from dual; -
修改字符集为 SIMPLIFIED CHINESE_CHINA.ZHS16GBK
-- operation requires database is in RESTRICTED mode alter system enable restricted session; alter system set nls_language='SIMPLIFIED CHINESE' scope = spfile; alter system set nls_territory='CHINA' scope=spfile; alter database character set internal_use ZHS16GBK; -
重启数据库
shutdown immediate; startup;
六、导入数据
将你导出的dmp文件放到之前的oracleinstaller文件夹里面,在docker容器中就可以看到这个文件了
imp username/password@127.0.0.1:1521/orcl file=/install/your.dmp full=y ignore=y log=/install/imp.log
默认的表空间 USERS 大小为32G,如果你导入的数据比较大可以增加表空间文件来扩大表空间
alter tablespace USERS add datafile '/opt/oracle/app/oradata/orcl/users02.DBF' size 32000M;
注意单个表空间文件最大不能超过32G
查看表空间占用
select Upper(f.tablespace_name),d.tot_grootte_mb "tb_size(G)",d.tot_grootte_mb - f.total_bytes "tb_use(G)",
to_char(round((d.tot_grootte_mb - f.total_bytes)/d.tot_grootte_mb * 100, 2),'990.99') || '%' "tb_percent",
f.total_bytes "tb_last(G)"
from (select tablespace_name,round(sum(bytes) / (1024 * 1024 * 1024), 2) total_bytes, round(max(bytes) / (1024 * 1024 * 1024), 2) max_bytes
from sys.dba_free_space group by tablespace_name) f,(select dd.tablespace_name,round(sum(dd.bytes) / (1024 * 1024 * 1024), 2) tot_grootte_mb
from sys.dba_data_files dd group by dd.tablespace_name) d where d.tablespace_name = f.tablespace_name
order by f.tablespace_name;
文章来源:
https://www.jianshu.com/p/f26425f0a218
https://jingyan.baidu.com/article/9f63fb91b786d5c8400f0eec.html


4523

被折叠的 条评论
为什么被折叠?



