目录

雪月书韵茶香

昨夜西风凋碧树,独上高楼,望尽天涯路


X

deepin使用docker安装oracle并解锁scott用户

docker安装oracle

使用docker拉取oracle11g的镜像

sudo docker pull  docker.io/arahman/docker-oracle-xe-11g

查看镜像

sudo docker images

创建容器并启动

docker run -d -v /home/xysycx/Software/docker/oracle11g:/data/oracle_data -p 49160:22 -p 1521:1521 -e ORACLE_ALLOW_REMOTE=true docker.io/arahman/docker-oracle-xe-11g

参数解释

 -d 后台运行
 -v 将本地目录/home/xysycx/Software/docker/oracle11g挂载到docker的/data/oracle_data目录下
 -p 将本地端口映射到容器的虚拟端口 :前为本地端口,:后为需要映射的虚拟端口。
 -e ORACLE_ALLOW_REMOTE表示是否允许远程连接

此处我特意设置两个地址不一样,方便你理解docker如何将本地文件夹映射到docker容器内部的
/home/xysycx/Software/docker/oracle11g 是我本机linux系统的文件路径
如果我要在docker oracle内部访问这个路径就需要 指定的路径是/data/oracle_data

截图录屏_deepin-terminal_20201123003419

到此oracle安装启动完成

那么问题来了,我挂在一个本地文件夹到到docker oracle中有何贵干呢?
因为docker下的oracle 没有Scott用户,也就无法使用scott用户下的默认的几张练习用的表
BONUS
DEPT
EMP
SALGRADE

接下来我们来解决这个问题

生成scott用户和相关练习用的表

进入docker容器目录

sudo docker exec -it 524852505bf7 /bin/bash

记得将524852505bf7替换为你的容器id

找到一个文件叫utlsampl.sql

cat utlsampl.sql

然后控制台会给你打印出如下内容

Rem Copyright (c) 1990, 2006, Oracle. All rights reserved.  
Rem NAME
REM    UTLSAMPL.SQL
Rem  FUNCTION
Rem  NOTES
Rem  MODIFIED
Rem     lburgess   04/02/06  - lowercase passwords 
Rem     menash     02/21/01 -  remove unnecessary users for security reasons
Rem     gwood      03/23/99 -  make all dates Y2K compliant
Rem     jbellemo   02/27/97 -  dont connect as system
Rem     akolk      08/06/96 -  bug 368261: Adding date formats
Rem     glumpkin   10/21/92 -  Renamed from SQLBLD.SQL 
Rem     blinden   07/27/92 -  Added primary and foreign keys to EMP and DEPT
Rem     rlim       04/29/91 -         change char to varchar2 
Rem     mmoore     04/08/91 -         use unlimited tablespace priv 
Rem     pritto     04/04/91 -         change SYSDATE to 13-JUL-87 
Rem   Mendels    12/07/90 - bug 30123;add to_date calls so language independent
Rem
rem 
rem $Header: utlsampl.sql 02-apr-2006.21:13:01 lburgess Exp $ sqlbld.sql 
rem 
SET TERMOUT OFF
SET ECHO OFF

rem CONGDON    Invoked in RDBMS at build time.   29-DEC-1988
rem OATES:     Created: 16-Feb-83
 
DROP USER SCOTT CASCADE;
DROP USER ADAMS CASCADE;
DROP USER JONES CASCADE;
DROP USER CLARK CASCADE;
DROP USER BLAKE CASCADE;
GRANT CONNECT,RESOURCE,UNLIMITED TABLESPACE TO SCOTT IDENTIFIED BY tiger;
DROP PUBLIC SYNONYM PARTS;

CONNECT SCOTT/tiger
CREATE TABLE DEPT
       (DEPTNO NUMBER(2) CONSTRAINT PK_DEPT PRIMARY KEY,
        DNAME VARCHAR2(14) ,
        LOC VARCHAR2(13) ) ;
CREATE TABLE EMP
       (EMPNO NUMBER(4) CONSTRAINT PK_EMP PRIMARY KEY,
        ENAME VARCHAR2(10),
        JOB VARCHAR2(9),
        MGR NUMBER(4),
        HIREDATE DATE,
        SAL NUMBER(7,2),
        COMM NUMBER(7,2),
        DEPTNO NUMBER(2) CONSTRAINT FK_DEPTNO REFERENCES DEPT);
INSERT INTO DEPT VALUES
        (10,'ACCOUNTING','NEW YORK');
INSERT INTO DEPT VALUES (20,'RESEARCH','DALLAS');
INSERT INTO DEPT VALUES
        (30,'SALES','CHICAGO');
INSERT INTO DEPT VALUES
        (40,'OPERATIONS','BOSTON');
INSERT INTO EMP VALUES
(7369,'SMITH','CLERK',7902,to_date('17-12-1980','dd-mm-yyyy'),800,NULL,20);
INSERT INTO EMP VALUES
(7499,'ALLEN','SALESMAN',7698,to_date('20-2-1981','dd-mm-yyyy'),1600,300,30);
INSERT INTO EMP VALUES
(7521,'WARD','SALESMAN',7698,to_date('22-2-1981','dd-mm-yyyy'),1250,500,30);
INSERT INTO EMP VALUES
(7566,'JONES','MANAGER',7839,to_date('2-4-1981','dd-mm-yyyy'),2975,NULL,20);
INSERT INTO EMP VALUES
(7654,'MARTIN','SALESMAN',7698,to_date('28-9-1981','dd-mm-yyyy'),1250,1400,30);
INSERT INTO EMP VALUES
(7698,'BLAKE','MANAGER',7839,to_date('1-5-1981','dd-mm-yyyy'),2850,NULL,30);
INSERT INTO EMP VALUES
(7782,'CLARK','MANAGER',7839,to_date('9-6-1981','dd-mm-yyyy'),2450,NULL,10);
INSERT INTO EMP VALUES
(7788,'SCOTT','ANALYST',7566,to_date('13-JUL-87','dd-mm-rr')-85,3000,NULL,20);
INSERT INTO EMP VALUES
(7839,'KING','PRESIDENT',NULL,to_date('17-11-1981','dd-mm-yyyy'),5000,NULL,10);
INSERT INTO EMP VALUES
(7844,'TURNER','SALESMAN',7698,to_date('8-9-1981','dd-mm-yyyy'),1500,0,30);
INSERT INTO EMP VALUES
(7876,'ADAMS','CLERK',7788,to_date('13-JUL-87', 'dd-mm-rr')-51,1100,NULL,20);
INSERT INTO EMP VALUES
(7900,'JAMES','CLERK',7698,to_date('3-12-1981','dd-mm-yyyy'),950,NULL,30);
INSERT INTO EMP VALUES
(7902,'FORD','ANALYST',7566,to_date('3-12-1981','dd-mm-yyyy'),3000,NULL,20);
INSERT INTO EMP VALUES
(7934,'MILLER','CLERK',7782,to_date('23-1-1982','dd-mm-yyyy'),1300,NULL,10);
CREATE TABLE BONUS
        (
        ENAME VARCHAR2(10)      ,
        JOB VARCHAR2(9)  ,
        SAL NUMBER,
        COMM NUMBER
        ) ;
CREATE TABLE SALGRADE
      ( GRADE NUMBER,
        LOSAL NUMBER,
        HISAL NUMBER );
INSERT INTO SALGRADE VALUES (1,700,1200);
INSERT INTO SALGRADE VALUES (2,1201,1400);
INSERT INTO SALGRADE VALUES (3,1401,2000);
INSERT INTO SALGRADE VALUES (4,2001,3000);
INSERT INTO SALGRADE VALUES (5,3001,9999);
COMMIT;
EXIT

然后将文本最后一行的exit 删除后再复制到因另外一部分文件,命名为scott.sql
存放到你挂载的本地文件夹
截图录屏_选择区域_20201123004901

就是这样。

以sysdba身份登录sqlplus

sqlplus sys/oracle as sysdba

执行sql文件

@ /data/oracle_data/scott.sql

显示用户

show user

查看用户SCOTT的表

select * from tab;

截图录屏_选择区域_20201123005135

nice!!!

登录scott用户

conn scott/tiger;

显示结果如下

SQL> conn scott/tiger;
Connected.                                                                                                                                                     
SQL>

哦对了,这里tiger就是scott的密码

接下来我们尝试使用专业的连接工具来连接oracle
比如DataGrip

enter description here
DataGrip连接成功,没得问题!

DataGrip连接成功后会耐心等待一下,才能看到scott用户下的表。

截图录屏_jetbrains-datagrip_20201123010827

完事大吉,收工睡觉。


标题:deepin使用docker安装oracle并解锁scott用户
作者:shuaibing90
版权声明:本站所有文章除特别声明外,均采用 CC BY-SA 4.0转载请于文章明显位置附上原文出处链接和本声明
地址:https://xysycx.cn/articles/2020/11/23/1606065229665.html
欢迎加入博主QQ群点击加入群聊:验证www.xysycx.cn