Connecting To Oracle Database: Difference between revisions
m (Also add Vim to allow for `ed` editing mode) |
m (Added page to Database category) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
Connecting to a Oracle database directly does not seem to be possible due to the driver being compiled for GNU libc and it being proprietary. It is possible to connect to | Connecting to a Oracle database directly does not seem to be possible due to the driver being compiled for GNU libc and it being proprietary. It is possible to connect to one database using Docker however. The image is proprietary as well, so a <code>docker login</code> is required and the "Proceed to Checkout" on https://hub.docker.com/_/oracle-instant-client has to be went through. | ||
== | == Create the environment == | ||
First, create the container and mount the current directory: | |||
<pre> | <pre> | ||
docker run - | docker run --name okcli -v ${PWD}:/data -d -e LC_CTYPE=en_US.UTF-8 store/oracle/database-instantclient:12.2.0.1 sh -c "yum update -y && yum install -y python3-pip util-linux vim && pip3 install okcli && tail -f /dev/null" | ||
</pre> | </pre> | ||
You may check if the installation has finished by running: | |||
[https://en.wikipedia.org/wiki/SQL_Plus SQL Plus] is the proprietary CLI to access a Oracle database. You can connect using it | <pre> | ||
docker logs -f okcli | |||
</pre> | |||
Now, whenever you need to connect to a database, run the following: | |||
<pre> | |||
docker restart okcli && docker exec -it okcli sh -c "cd /data && sh" | |||
</pre> | |||
== Option 1: Connecting with with <code>okcli</code> == | |||
<code>[https://github.com/man-group/okcli okcli]</code> is a libre CLI to access a Oracle database. You can connect using it by now entering the following command in the prompt from above: | |||
<pre> | |||
okcli 'myusername/mypassword@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=141.62.75.20)(Port=1521))(CONNECT_DATA=(SID=DB1)))' | |||
</pre> | |||
You can run a script in the directory you've mounted above like so: | |||
<pre> | |||
okcli 'myusername/mypassword@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=141.62.75.20)(Port=1521))(CONNECT_DATA=(SID=DB1)))' -@ myscript.sql | |||
</pre> | |||
== Option 2: Connecting with with SQL Plus == | |||
[https://en.wikipedia.org/wiki/SQL_Plus SQL Plus] is the proprietary CLI to access a Oracle database. You can connect using it by now entering the following command in the prompt from above: | |||
<pre> | <pre> | ||
sqlplus 'myusername/mypassword@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=141.62.75.20)(Port=1521))(CONNECT_DATA=(SID=DB1)))' | |||
</pre> | </pre> | ||
You can run a script in the directory you've mounted above like so: | |||
<pre> | |||
sqlplus 'myusername/mypassword@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=141.62.75.20)(Port=1521))(CONNECT_DATA=(SID=DB1)))' @myscript.sql | |||
</pre> | |||
[[Category:Database]] |
Latest revision as of 19:20, 4 September 2023
Connecting to a Oracle database directly does not seem to be possible due to the driver being compiled for GNU libc and it being proprietary. It is possible to connect to one database using Docker however. The image is proprietary as well, so a docker login
is required and the "Proceed to Checkout" on https://hub.docker.com/_/oracle-instant-client has to be went through.
Create the environment
First, create the container and mount the current directory:
docker run --name okcli -v ${PWD}:/data -d -e LC_CTYPE=en_US.UTF-8 store/oracle/database-instantclient:12.2.0.1 sh -c "yum update -y && yum install -y python3-pip util-linux vim && pip3 install okcli && tail -f /dev/null"
You may check if the installation has finished by running:
docker logs -f okcli
Now, whenever you need to connect to a database, run the following:
docker restart okcli && docker exec -it okcli sh -c "cd /data && sh"
Option 1: Connecting with with okcli
okcli
is a libre CLI to access a Oracle database. You can connect using it by now entering the following command in the prompt from above:
okcli 'myusername/mypassword@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=141.62.75.20)(Port=1521))(CONNECT_DATA=(SID=DB1)))'
You can run a script in the directory you've mounted above like so:
okcli 'myusername/mypassword@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=141.62.75.20)(Port=1521))(CONNECT_DATA=(SID=DB1)))' -@ myscript.sql
Option 2: Connecting with with SQL Plus
SQL Plus is the proprietary CLI to access a Oracle database. You can connect using it by now entering the following command in the prompt from above:
sqlplus 'myusername/mypassword@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=141.62.75.20)(Port=1521))(CONNECT_DATA=(SID=DB1)))'
You can run a script in the directory you've mounted above like so:
sqlplus 'myusername/mypassword@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=141.62.75.20)(Port=1521))(CONNECT_DATA=(SID=DB1)))' @myscript.sql