文章目录
Oracle环境:
查询docker镜像
docker search oracle
结果:
[root@VM_0_2_centos app]# docker search oracle
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
oraclelinux Official Docker builds of Oracle Linux. 641 [OK]
jaspeen/oracle-11g Docker image for Oracle 11g database 155 [OK]
oracleinanutshell/oracle-xe-11g 88
oracle/openjdk Docker images containing OpenJDK Oracle Linux 60 [OK]
oracle/graalvm-ce GraalVM Community Edition Official Image 59 [OK]
absolutapps/oracle-12c-ee Oracle 12c EE image with web management cons… 38
araczkowski/oracle-apex-ords Oracle Express Edition 11g Release 2 on Ubun… 29 [OK]
oracle/nosql Oracle NoSQL on a Docker Image with Oracle L… 23 [OK]
bofm/oracle12c Docker image for Oracle Database 23 [OK]
datagrip/oracle Oracle 11.2 & 12.1.0.2-se2 & 11.2.0.2-xe 18 [OK]
truevoly/oracle-12c Copy of sath89/oracle-12c image (https://git… 13
oracle/weblogic-kubernetes-operator Docker images containing the Oracle WebLogic… 11
openweb/oracle-tomcat A fork off of Official tomcat image with Ora… 8 [OK]
iamseth/oracledb_exporter A Prometheus exporter for Oracle modeled aft… 3
softwareplant/oracle oracle db 2 [OK]
paulosalgado/oracle-java8-ubuntu-16 Oracle Java 8 on Ubuntu 16.04 LTS. 2 [OK]
18fgsa/oracle-client Hosted version of the Oracle Container Image… 2
roboxes/oracle7 A generic Oracle Linux 7 base image. 1
publicisworldwide/oracle-core This is the core image based on Oracle Linux… 1 [OK]
bitnami/oraclelinux-runtimes Oracle Linux runtime-optimized images 0 [OK]
bitnami/oraclelinux-extras Oracle Linux base images 0 [OK]
arm64v8/oraclelinux Official Docker builds of Oracle Linux. 0
toolsmiths/oracle7-test 0
pivotaldata/oracle7-test Oracle Enterprise Linux (OEL) image for GPDB… 0
amd64/oraclelinux Official Docker builds of Oracle Linux. 0
下载镜像
docker pull marcocimatti/oracle12.2.0.1-se2
创建文件夹并授权(用于挂载)
mkdir /data && chmod 777 /data
启动
docker run --restart always -d -p 8080:8080 -p 1521:1521 -e ORACLE_PWD=Shopxx1234 -v /data:/opt/oracle/oradata -v /etc/localtime:/etc/localtime:ro --name shopxx-b2b2c-oracle marcocimatti/oracle12.2.0.1-se2
查看安装进度
docker logs -f 3f38045ecf2a41d2a76e9d5f525133ce28f16cd0bd7a723286756b22d2d09338
安装完成则Ctrl+C退出
查看容器
docker ps
结果
[root@VM_0_2_centos data_temp]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6f1c2f5372b5 truevoly/oracle-12c "/entrypoint.sh " 9 minutes ago Up 9 minutes 0.0.0.0:1521->1521/tcp, 0.0.0.0:8080->8080/tcp orac
d9fe468f1d89 mysql:5.7 "docker-entrypoint.s…" 2 hours ago Up 17 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
进入容器
docker exec -it 6f1c2f5372b5 /bin/bash
进入Oracle
sqlplus system/Shopxx1234@//localhost:1521/ORCLPDB1
成功。使用pl/sql连接时,ORCLPDB1是这个镜像默认的服务
查看oracle现在的状态
状态为 OPEN 则正常
select status from v$instance;
创建账户
create user 账户 identified by 密码;
(create user shopxx identified by Shopxx1234;)
创建用户名为shopxx密码为Shopxx1234的账户
授权
grant create session to shopxx;
grant connect,resource,dba to shopxx;
提交
commit;
JDBC:
依赖
runtimeOnly("com.oracle.ojdbc:ojdbc8:19.3.0.0")
application-dev.yml
server:
port: 8080
spring:
datasource:
driver-class-name: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@localhost:1521/ORCLPDB1
username: shopxx
password: Shopxx1234
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.Oracle12gDialect
messages:
basename: classpath:/language/common/message,classpath:/language/shop/message,classpath:/language/member/message,classpath:/language/business/message,classpath:/language/admin/message
ORCLPDB1是服务名(Service Name/SID)
Tips
- 所有字段(表名 字段名等)命名不能超过30个字符集 (Oracle 版本 12.2 之前,标识符的长度不允许超过 30 个字符 但是,从 12.2 版开始,它们的长度可达 128 个字节[注意:字节,不是字符])
- 插入字符串不能过长 使用
to_clob('xxxxxxxxx')
函数处理过长字符串 但不能鲁莽的包裹整个字符串 因为to_clob()函数接受的参数也有长度显示 所以适当截取作为参数传递给to_clob()函数 之后的字符串使用||
连接符进行拼接即可(在使用了chr(10)等常量时 要使用to_clob()包裹常量 如to_clob('xxxxxxxxxxx' || chr(10)) || to_clob('xxxxxxxxxxx' || chr(10))
) - 单引号存入数据库时 要用两个单引号(
''
)而不是\'
账户信息
可以使用客户端链接了:
账号:shopxx
密码:Shopxx1234
端口:1521
服务名称:ORCLPDB1
查询所有账户
SELECT * FROM ALL_USERS;
获取数据库的服务名称
select value from v$parameter where name='service_names';
操作命令备份
--首先查询一下用户的profile的类型
select username ,profile from dba_users;
--查看制定概要文件(默认为DEFAULT)的密码有效期:
select * from dba_profiles where profile='DEFAULT' and resource_name='PASSWORD_LIFE_TIME';
--然后将密码的有效期有180天设置为“无限制”;
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
-- 修改密码
alter user hysjy identified by 123456;
-- 查询所有用户
SELECT * FROM ALL_USERS;
-- 创建账户
create user hysjy identified by 123456;
GRANT CONNECT, RESOURCE, DBA TO hysjy;
-- 给用户授予权限
grant create session to hysjy;
grant connect,resource to hysjy;
-- 解除锁定
alter user hysjy account unlock;
commit;