目 录CONTENT

文章目录

Oracle容器密码修改

BKUN
2024-12-13 / 0 评论 / 0 点赞 / 532 阅读 / 553 字

🚀 Docker 容器操作:进入 Oracle 并修改密码

这是一个在 Docker 容器中操作 Oracle 数据库的指南,展示了如何进入容器、使用 SQL*Plus 并重置用户密码。让我们一步步完成吧!📜


📝 操作步骤

1️⃣ 进入 Docker 容器

假设容器名为 oracle12c(根据实际名称替换),执行以下命令:

docker exec -it oracle12c bash

💡 提示-it 表示交互模式,bash 进入容器的 Shell 环境。

示例输出

root@a61a51311505:/#

2️⃣ 定位 SQL*Plus

确认 SQL*Plus 的路径:

which sqlplus

📌 输出/u01/app/oracle/product/12.1.0/xe/bin/sqlplus


3️⃣ 切换到 Oracle 用户

root 用户进入后,切换到 oracle 用户:

su - oracle

🌟 效果:权限变更为 Oracle 用户,环境变量自动配置。

示例输出

oracle@a61a51311505:/$

4️⃣ 启动 SQL*Plus

运行 SQL*Plus 并以 sysdba 身份登录:

/u01/app/oracle/product/12.1.0/xe/bin/sqlplus / as sysdba

⚙️ 说明/ as sysdba 使用操作系统认证登录,无需密码。

示例输出

SQL*Plus: Release 12.1.0.2.0 Production on Fri Dec 13 01:05:00 2024
Copyright (c) 1982, 2014, Oracle.  All rights reserved.
Connected to an idle instance.
SQL>

5️⃣ 修改用户密码

在 SQL*Plus 中重置指定用户密码,例如将 myuser 的密码改为 mynewpassword

alter user myuser identified by mynewpassword;

结果:密码修改成功。

注意

  • 若用户不存在,先创建:
    create user myuser identified by mynewpassword;
    grant connect, resource to myuser;
    

6️⃣ 退出 SQL*Plus

完成操作后退出:

exit

⏏️ 效果:返回容器 Shell。

示例输出

oracle@a61a51311505:/$

🔧 使用技巧

  1. 查看容器名称
    docker ps -a
    
  2. 直接运行 SQL*Plus(无需进入容器):
    docker exec -it oracle12c /u01/app/oracle/product/12.1.0/xe/bin/sqlplus / as sysdba
    
  3. 密码复杂性:确保新密码符合 Oracle 策略(如长度、字符要求)。
  4. 退出容器
    exit  # 从 oracle 用户退出到 root
    exit  # 从容器退出到宿主机
    

操作完成!
你已成功进入 Docker 容器并修改了 Oracle 用户密码。😄👍

0

评论区