Establish Database Connections from Python

Published by onesixx on

https://appsilon.com/post/shiny-for-python-databases-mysql-postgres

df = pd.read_sql(stmt, con=conn)

Oralce

https://hub.docker.com/r/gvenzl/oracle-xe

download docker Image

docker pull gvenzl/oracle-xe:latest

Image를 Container화

Run a new persistent database container (data is kept throughout container lifecycles):

docker run -d -p 1521:1521 -e ORACLE_PASSWORD=password -v oracle-volume:/opt/oracle/oradata gvenzl/oracle-xe

❯ docker ps

❯ docker exec -it compassionate_shirley bash
❯ docker exec -it compassionate_shirley sqlplus

bash-4.4$ cd /opt/human_resources/
bash-4.4$ ls -al
total 104
drwxrwxr-x 2  501 games  4096 Mar 28 16:32 .
drwxr-xr-x 1 root root   4096 May 19 11:54 ..
-rw-rw-r-- 1  501 games  2642 Mar 28 16:32 README.md
-rw-rw-r-- 1  501 games  2666 Mar 28 16:32 README.txt
-rw-rw-r-- 1  501 games  3849 Mar 28 16:32 hr_code.sql
-rw-rw-r-- 1  501 games 17112 Mar 28 16:32 hr_create.sql
-rw-rw-r-- 1  501 games  8275 Mar 28 16:32 hr_install.sql
-rw-rw-r-- 1  501 games 41301 Mar 28 16:32 hr_populate.sql
-rw-rw-r-- 1  501 games  2920 Mar 28 16:32 hr_uninstall.sql

bash-4.4$ cd /opt/oracle/product/21c/dbhomeXE
bash-4.4$ cd demo/shema
bash-4.4$ pwd
/opt/oracle/product/21c/dbhomeXE/demo/schema
bash-4.4$ cp -rf /opt/human_resources/ ./
❯ docker exec -it compassionate_shirley sqlplus
system
password

SQL> @?/demo/schema/human_resources/hr_create.sql
SQL> @?/demo/schema/human_resources/hr_populate.sql
SQL> @?/demo/schema/human_resources/hr_install.sql
ORA-01918: 사용자 'HR'(이)가 존재하지 않습니다 (Oracle18c XE HR계정 생성)
Oracle18c XE 다운로드 후 SQL Developer 에서 HR계정을 사용하기 위해 
SQLPlus에서 HR 계정을 LOCK에서 UNLOCK으로 변경시도 했지만

ORA-01918: 사용자 'HR'(이)가 존재하지 않습니다 와 같은 오류가 뜨는 것은
HR 계정이 존재하지 않기 때문입니다. 

SQLPlus 에서 HR 스키마를 설치해야합니다.
 
SQL > ALTER SESSION SET "_ORACLE_SCRIPT" = true;

SQL> @?/demo/schema/human_resources/hr_install.sql 
@는 sql파일실행, ?는 $ORACLE_HOME 즉 여기서는 /opt/oracle/product/21c/dbhomeXE


 specify password for HR as parameter 1
(1의 값을 입력하십시오) : password


 specify default tablespeace for HR as parameter 2
( 2의 값을 입력하십시오) : users



 
 
[Database/Oracle] SQL Developer 설치 및 준비 
게시글로 이동해 SQL Developer에 HR계정 추가하는 방법을 볼 수 있습니다.
 
< HR 계정 사용하기 위한 SQLPlus 설정 >
1)HR 계정은 처음에 기본적으로 LOCK 걸려 있으므로, UNLOCK으로 변경해줘야 사용가능합니다.

SQL> alter user hr account unlock;

User altered.

SQL> alter user hr identified by password;

User altered.
Categories: shiny

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x