简体   繁体   English

如何在 Windows 10 上获取 ORACLE 11 g DATABASE 的 IP 地址以远程连接到它?

[英]How do i get the IP address of ORACLE 11 g DATABASE on windows 10 to remotely connect to it?

I have installed oracle 11g on windows 10 f drive of my laptop.我已经在我的笔记本电脑的 Windows 10 f 驱动器上安装了 oracle 11g。 I want know the IP address of the database in order to connect to it using python?我想知道数据库的 IP 地址以便使用 python 连接到它? How do i find the ip address?我如何找到IP地址?

I tried this command: select sys_context('USERENV','IP_ADDRESS') from dual;我试过这个命令: select sys_context('USERENV','IP_ADDRESS') from dual; however it gives me the local host address.但是它给了我本地主机地址。

i also tried SELECT UTL_INADDR.get_host_address from dual;我也试过 SELECT UTL_INADDR.get_host_address from dual; however this throws an error saying network access denied by access control list但是这会抛出一个错误,说网络访问被访问控制列表拒绝

how do i find out the IP address?我如何找出IP地址?

You must have a TNSNAMES.ORA file in your Oracle Configuration.您的 Oracle 配置中必须有TNSNAMES.ORA文件。 Find that file and open it.找到那个文件并打开它。 There should be ip adresses and needed ports in there.那里应该有 ip 地址和所需的端口。

From official docs:来自官方文档:

By default, tnsnames.ora is located in the $ORACLE_HOME/network/admin directory on UNIX operating systems and in the %ORACLE_HOME%\\network\\admin directory on Windows operating systems.默认情况下,tnsnames.ora 在 UNIX 操作系统上位于 $ORACLE_HOME/network/admin 目录中,在 Windows 操作系统上位于 %ORACLE_HOME%\\network\\admin 目录中。 tnsnames.ora can also be stored the following locations: tnsnames.ora 也可以存储在以下位置:

The directory specified by the TNS_ADMIN environment variable or registry value TNS_ADMIN 环境变量或注册表值指定的目录

On UNIX operating systems, the global configuration directory.在 UNIX 操作系统上,全局配置目录。 For example, on the Solaris Operating System, this directory is /var/opt/oracle.例如,在 Solaris 操作系统上,此目录为 /var/opt/oracle。

Then you can connect db with python cx_Oracle library using syntax below for connection string.然后,您可以使用以下连接字符串的语法将 db 与 python cx_Oracle库连接。

connection_oracle_textfile.txt -> username/password@HOST:PORT/SERVICE_NAME (you can find all of them but username and password in tnsnames.ora file) connection_oracle_textfile.txt -> username/password@HOST:PORT/SERVICE_NAME (您可以在 tnsnames.ora 文件中找到除用户名和密码之外的所有这些)

import cx_Oracle as cx_Oracle
def get_oracle_table_from_dbm(sql_text):
if 'connection_oracle' not in  globals():
    print('connection does not exist. Try to connect it...')
    f = open('connection_oracle_textfile.txt', "r")
    fx = f.read()         
    ####
    global connection_oracle
    connection_oracle = cx_Oracle.connect(fx)
    ####
    print('connection established!!')

print('Already have connection. Just fetch data!!')
return pd.read_sql(sql_text, con=connection_oracle)

Docs 文档

There is no IP Address assigned to the Oracle database.没有分配给 Oracle 数据库的 IP 地址。 In your case, The database is installed on your own machine so the IP ADDRESS of the database is the same as the IP ADDRESS of your own machine.在您的情况下,数据库安装在您自己的机器上,因此数据库的 IP 地址与您自己机器的 IP 地址相同。

select sys_context('USERENV','IP_ADDRESS') from dual;

The aforementioned query gives the IP ADDRESS of the client which is connected to the database.上述查询给出了连接到数据库的客户端的 IP 地址。 I think you are misunderstood by this one - It is not the database' IP ADDRESS.我认为你被这个误解了 - 这不是数据库的 IP 地址。

If you need the HOST_NAME of the database then you can use the following query.如果您需要数据库的HOST_NAME ,则可以使用以下查询。 Note that HOAST_NAME can be used to connect to the database in the connection string or in TNS_NAMES.ora请注意, HOAST_NAME可用于在连接字符串或TNS_NAMES.ora 中连接到数据库

SQL> SELECT INSTANCE_NAME, HOST_NAME FROM V$INSTANCE; INSTANCE_N HOST_NAME ---------- -------------------- orcl DESKTOP-0****** SQL>

I hope it will clear all your doubts.我希望它能消除你所有的疑虑。

Cheers!!干杯!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM