docker安装oracle
# 下载镜像 19.3.0.0.0
docker pull registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c
# 创建文件
mkdir -p /home/mymount/oracle19c/oradata
mkdir -p /home/mymount/oracle23c/oradata
# 授权,不授权会导致后面安装失败
chmod 777 /home/mymount/oracle19c/oradata
chmod 777 /home/mymount/oracle23c/oradata
docker run -d \
-p 1521:1521 -p 5500:5500 \
-e ORACLE_SID=SID \
-e ORACLE_PDB=PDB \
-e ORACLE_PWD=123456 \
-e ORACLE_EDITION=standard \
-e ORACLE_CHARACTERSET=AL32UTF8 \
-v /home/mymount/oracle19c/oradata:/opt/oracle/oradata \
--name oracle19c \
registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c
# 查看日志,等待加载进度(初次加载比较慢)
docker logs -tf oracle19c
# 等待过程可能会比较漫长,成功的日志:
#########################
DATABASE IS READY TO USE!
#########################
# 连接数据库登录 默认账号密码:sys/123456
docker exec -it oracle19c /bin/bash
sqlplus sys/123456@localhost:1521/pdb as sysdba;
查看日志是否安装成功
docker logs -ft 容器名
docker logs -ft orcl19c
docker container ls -a命令查看容器名
sys 用户登录容器
### 打开容器
docker exec -it oracle19c /bin/bash
sqlplus sys/123456@localhost:1521/pdb as sysdba;
show pdbs;
docker exec -it oracle23 /bin/bash
sqlplus sys/123456@localhost:1523 as sysdba;
sys 用户登录容器创建表空间以及用户
-- 查询数据库实例的名称,也就是 ORACLE_SID 的值 -- 默认是 xe
SELECT name FROM v$database;
-- 查看oracle现在的状态 ,状态为 OPEN 则正常
select status from v$instance;
-- 查看所有表空间(相当于mysql中的库)
SELECT name FROM v$tablespace;
-- 创建表空间
-- mkdir -p /home/oracle/escdb
-- chmod 777 /home/oracle/escdb
sqlplus sys/123456@localhost:1521/pdb as sysdba;
CREATE TABLESPACE EDU DATAFILE '/opt/oracle/oradata/SID/PDB/ZS_EDU.dbf' SIZE 100M AUTOEXTEND ON MAXSIZE 500M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;
-- 查询所有用户名
-- select username from all_users;
select username from user_users;
-- 创建用户
CREATE USER IAM IDENTIFIED BY 123456 DEFAULT TABLESPACE idm_spc;
===========================================
CREATE USER ZS_EDU IDENTIFIED BY 123456 DEFAULT TABLESPACE edu;
-- 分配角色
ALTER USER ZS_EDU QUOTA UNLIMITED ON EDU;
GRANT CONNECT, RESOURCE TO IAM;
GRANT CONNECT, RESOURCE TO ZS_EDU;
-- 退出后登录,普通用户不需要指定角色类型
sqlplus zs_edu/123456@localhost:1521/pdb;
建表
(复制sql,替换表名执行完毕后,再修改自己想要的字段即可)
-- 查看当前数据库中用户的所有表
-- SELECT table_name FROM user_tables;
-- 创建表
CREATE TABLE IAM.test_table (
id NUMBER(10,0) VISIBLE NOT NULL,
name VARCHAR2(255 BYTE) VISIBLE,
create_time TIMESTAMP(6) VISIBLE DEFAULT CURRENT_TIMESTAMP NOT NULL,
update_time TIMESTAMP(6) VISIBLE DEFAULT CURRENT_TIMESTAMP NOT NULL,
del NUMBER(1,0) VISIBLE DEFAULT 0 NOT NULL,
primary key(id)
) TABLESPACE IDM_SPC;
-- 设置字段备注
COMMENT ON COLUMN IAM.test_table.id IS '主键id';
COMMENT ON COLUMN IAM.test_table.name IS '名称';
COMMENT ON COLUMN IAM.test_table.create_time IS '创建时间';
COMMENT ON COLUMN IAM.test_table.update_time IS '修改时间';
COMMENT ON COLUMN IAM.test_table.del IS '是否已删除 0:否 1:是';
-- 设置主键自增 表名:test_table (主键已存在就不需要再创建,在创建报错,可以跳过这步操作)
-- alter table test_table add constraint id primary key (id);
-- 自定义序列名 test_table_seq
create sequence test_table_seq
increment by 1
start with 1
nomaxvalue
nominvalue
nocache;
-- 创建触发器
create or replace trigger test_table_seq
before insert on test_table for each row
begin
select test_table_seq.nextval into :new.id from dual;
end;
以下是docker 安装oracle常用命令
什么是pdb数据库?什么是CDB?
参照https://blog.csdn.net/weixin_39876739/article/details/111605869
如何切换PDB数据库
1. 用sys用户登录数据库
2. show con_name;
3. 3、 执行select name,open_mode from v$pdbs;
切换为pdb数据库
alter session set container=ORCLPDB;
查找用户
select userName from dba_users;
查看有哪些表空间
select tableSpace_name from Dba_tablespaces;
删除用户以及表结构(参照:https://blog.csdn.net/daxiang52/article/details/50408312)
drop user ZS_EDU cascade;
5 创建临时表空间
create temporary tablespace edu tempfile '/opt/oracle/oradata2' size 50m autoextend on next 50m maxsize 20480m extent management local;
===============================
oracle23
create temporary tablespace eduTem tempfile '/opt/oracle/oradata6' size 50m autoextend on next 50m maxsize 20480m extent management local;
6 创建表空间(查看有哪些表空间select tableSpace_name from Dba_tablespaces;)
create tablespace 表空间名称 logging datafile '数据存储路径' size 50m
autoextend on next 50m maxsize 20480m extent management local
=======================================
create tablespace edu1 logging datafile '/opt/oracle/oradata1' size 50m autoextend on next 50m maxsize 20480m extent management local;
----------------------------
oracle23
create tablespace edu logging datafile '/opt/oracle/oradata7' size 50m autoextend on next 50m maxsize 20480m extent management local;
删除表空间 Oracle删除表空间语法结构:(https://www.php.cn/faq/489137.html)
drop tablespace tab_name [including contents][cascade constraints]
案例、删除student表空间,并删除表空间的数据文件和完整性
drop tablespace student including contents cascade constraints;
7 创建用户并指定表空间
create user 用户名 identified by 密码 default tablespace 表空间名称 temporary tablespace 临时表空间名称;
create user ze_edu identified by zsShang886 default tablespace edu temporary tablespace eduTem;
=============================
create user zs_edu identified by zsShang886 default tablespace edu temporary tablespace eduTem;
8给用户授权
grant connect,resource,dba to 用户名;
9 用创建的用户名进行连接。
文章来源:https://www.toymoban.com/news/detail-656982.html
docker文件复制(参照https://blog.51cto.com/u_16175455/6724342)
docker cp /home/sql/ZS_EDU.sql oracle19c:/home
docker 执行sql文件
如果sql文件不在当前目录下,可以使用绝对路径:
>@D:/demo.sql
查看表空间有哪些表
select TABLE_NAME,TABLESPACE_NAME from dba_tables where TABLESPACE_NAME='表空间名';
docker 安装参照
https://blog.csdn.net/arcsin_/article/details/123707618
http://www.inspinia.net/a/14909.html?action=onClick(这个文章可以系统使得系统登陆)
https://blog.csdn.net/weixin_44032384/article/details/131404349(可以使得docker oracle执行sql)推荐这个老哥文章文章来源地址https://www.toymoban.com/news/detail-656982.html
到了这里,关于docker oracle linux命令执行sql的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!