[TIL][SQL]サーバへの接続


Oracleプログラムがインストールされている場合、Oracle Serverに管理者アカウントSYSSYSTEM、およびエクササイズ時に使用されるエクササイズアカウントSCOTTが生成されます.
C:\Users\user>sqlplus scott/tiger

SQL*Plus: Release 11.2.0.1.0 Production on1026 15:34:46 2020

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

다음에 접속됨:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
データベースが閉じており、練習アカウントに接続できません.エラーが発生しました.
C:\Users\user>sqlplus scott/tiger

SQL*Plus: Release 11.2.0.1.0 Production on1026 15:34:46 2020

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

ERROR:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
上記のエラーが発生した場合は、次のユーザー名入力部に管理者アカウントsysを入力して接続し、startupコマンドを使用してDBを起動します.
C:\Users\user>sqlplus

SQL*Plus: Release 11.2.0.1.0 Production on1026 15:40:19 2020

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

사용자명 입력: sys/oracle as sysdba

다음에 접속됨:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

15:40:28 SQL> startup
ORACLE instance started.

Total System Global Area ~~~~~~ bytes
~~~~
~~~~
~~~~
~~~~
Database mounted.
Database opened.
15:40:37 SQL> CONN scott/tiger
Connected.
現在接続されているアカウントshow userコマンドを確認します.SET sqlprompt "USER>"と入力すると、プロンプトの外観が現在の接続のアカウント名に変更されます.
15:43:55 SQL> set sqlpromp "_USER>"
15:44:13 SCOTT>
練習用口座に接続された時にORA-28000: the account is lockedという情報が出ると、セキュリティ上の問題で練習用口座scottの使用が阻止されるからだ.管理者アカウントに接続し、適切な操作を行った後、練習アカウントに再接続します.
C:\Users\user>sqlplus scott/tiger

SQL*Plus: Release 11.2.0.1.0 Production on1026 15:34:46 2020

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

ERROR:
ORA-28000: the account is locked

Enter user-name: sys/oracle as sysdba

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SYS>ALTER USER scott
  2  IDENTIFIED BY tiger
  3  ACCOUNT UNLOCK ;
  
User altered.

SYS>CONN scott/tiger
Connected.
SCOTT>
sysはoracleに対して最も高い権限を持つアカウントであり、/の後ろのoraclesysアカウントのパスワードでoracleを設定する際にsysアカウントに指定されたパスワードである.別のビル番号を設定したら、そのパスワードを入力すればいいです.