Oracle Database12c ORA 01918 和连接错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26591467/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 02:35:03  来源:igfitidea点击:

Oracle Database12c ORA 01918 and connection error

databaseoracleoracle12c

提问by user3389442

I have installed the Oracle 12c and I have problems creating my first database and using it. I run SQL Developer and use "hr" user but it keeps telling me that the account is locked. I searched into stackoverflow answers and official doc and tried to unlock it with:

我已经安装了 Oracle 12c,但在创建和使用我的第一个数据库时遇到了问题。我运行 SQL Developer 并使用“hr”用户,但它一直告诉我该帐户已被锁定。我搜索了 stackoverflow 的答案和官方文档,并尝试使用以下方法解锁它:

ALTER USER HR IDENTIFIED BY password ACCOUNT UNLOCK;

but with no success. I got error ORA01918, meaning that user does not exist.

但没有成功。我收到错误 ORA01918,这意味着该用户不存在。

I tried then to use the user created at the installation (SYS as SYSDBA)but then it says that the user/password is incorrect. I am pretty sure that I have installed Oracle 12c correctly on my system, which is Windows 8.1 x64.

然后我尝试使用在安装时创建的用户(SYS 作为 SYSDBA)但是它说用户/密码不正确。我很确定我已经在我的系统上正确安装了 Oracle 12c,它是 Windows 8.1 x64。

What should I do? Please help me.

我该怎么办?请帮我。

Other thing I do not understand is wether or not the term "database" is equivalent to MySQL's "Schema"? The "connection" is to connect to a specific database, yes? Thank you.

我不明白的另一件事是术语“数据库”是否等同于 MySQL 的“架构”?“连接”是连接到特定的数据库,是吗?谢谢你。

回答by Lalit Kumar B

How did you configure your database? Did you check the option for Pluggable database? If yes, please make sure you login to PDBand not CDB.

你是如何配置数据库的?你检查选项了Pluggable database吗?如果是,请确保您登录PDB而不是CDB

Please read Oracle 12c Post Installation Mandatory Steps.

请阅读Oracle 12c 安装后强制步骤

By default, pre-installedusers like SCOTT, HRetc. resides in container databaseand not in pluggable database.

默认情况下,pre-installedSCOTTHR等的用户驻留在container database和不在 中pluggable database

tnsnames.ora

tnsnames.ora

Edit your tnsnames.ora file to add the PDB details. For example,

编辑您的 tnsnames.ora 文件以添加 PDB 详细信息。例如,

PDBORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = pdborcl)
    )
  )

Open all PDBs

打开所有 PDB

To open all/specific PDBs immediately after logon, create a AFTER STARTUPsystem level trigger in CDB.

要在登录后立即打开所有/特定 PDB,请在 CDB 中创建AFTER STARTUP系统级触发器。

Since, the PDBs are not open through a CDB start. Let's see :

因为,PDB 不是通过 CDB 启动打开的。让我们来看看 :

SHUTDOWN IMMEDIATE;
STARTUP;

SQL> SELECT name, open_mode FROM v$pdbs;

NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDBP6                          MOUNTED

So, in order to have all the PDBs automatically open, do this :

因此,为了让所有 PDB 自动打开,请执行以下操作:

Do, “SQLPLUS / AS SYSDBA”, and then execute :

做“ SQLPLUS / AS SYSDBA”,然后执行:

CREATE OR REPLACE TRIGGER open_pdbs 
  AFTER STARTUP ON DATABASE 
BEGIN 
   EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN'; 
END open_pdbs;
/

It creates a after startup system level trigger in CDB.

它在 CDB 中创建启动后系统级触发器。

SQLPLUS / AS SYSDBA

SQLPLUS/AS SYSDBA

The most common misunderstanding is about “SQLPLUS / AS SYSDBA” usage.

最常见的误解是关于“SQLPLUS/AS SYSDBA”的用法。

Since we have checked the option to create a single CDB, the “SQLPLUS / AS SYSDBA” command will always log into CDB. Usually developers used to unlock the “SCOTT” account directly after logging as SYSDBA. But here is the trick :

由于我们已经选中了创建单个CDB的选项,因此“SQLPLUS / AS SYSDBA”命令将始终登录到 CDB。通常开发者在登录SYSDBA后直接解锁“SCOTT”账号。但这里有诀窍:

“SCOTT” and other sample schemas are in the PDB and not in the CDB. So, you need to login as sysdba into PDB.

“SCOTT”和其他示例模式位于 PDB 而不是 CDB 中。因此,您需要以 sysdba 身份登录到 PDB。

sqlplus SYS/password@PDBORCL AS SYSDBA

SQL> ALTER USER scott ACCOUNT UNLOCK IDENTIFIED BY tiger;

sqlplus scott/tiger@pdborcl

SQL> show user;
USER is "SCOTT"