# 下载镜像 19.3.0.0.0
docker pull registry.cn-hangzhou.aliyuncs.com/laowu/oracle:19c
# 创建文件
mkdir -p /home/mymount/oracle19c/oradata
# 授权,不授权会导致后面安装失败
chmod 777 /home/mymount/oracle19c/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 /mymount/oracle19c/oradata:/opt/oracle/oradata \
--name oracle19c \
registry.cn-hangzhou.aliyuncs.com/laowu/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 exec -it oracle19c /bin/bash
sqlplus sys/123456@localhost:1521/pdb as sysdba;
show pdbs;
-- 查询数据库实例的名称,也就是 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 idm_spc DATAFILE '/opt/oracle/oradata/SID/PDB/idm_spc.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;
-- 分配角色
GRANT CONNECT, RESOURCE TO IAM;
-- 退出后登录,普通用户不需要指定角色类型
sqlplus iam/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;
什么是pdb数据库?什么是CDB?
参照https://blog.csdn.net/weixin_39876739/article/details/111605869
1. 用sys用户登录数据库
2. show con_name;
3. 3、 执行select name,open_mode from v$pdbs;
alter session set container=ORCLPDB;
select userName from dba_users;
select tableSpace_name from Dba_tablespaces;
drop user ZS_EDU cascade;
create temporary tablespace edu tempfile '/opt/oracle/oradata2' 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
=======================================
create tablespace edu1 logging datafile '/opt/oracle/oradata1' size 50m autoextend on next 50m maxsize 20480m extent management local;
drop tablespace tab_name [including contents][cascade constraints]
案例、删除student表空间,并删除表空间的数据文件和完整性
drop tablespace student including contents cascade constraints;
create user 用户名 identified by 密码 default tablespace 表空间名称 temporary tablespace 临时表空间名称;
create user ze_edu identified by zsShang886 default tablespace edu temporary tablespace eduTem;
grant connect,resource,dba to 用户名;
docker cp /home/sql/ZS_EDU.sql oracle19c:/home
如果sql文件不在当前目录下,可以使用绝对路径:
>@D:/demo.sql
select TABLE_NAME,TABLESPACE_NAME from dba_tables where TABLESPACE_NAME='表空间名';
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)推荐这个老哥文章