使用 Oracle SQLcl 连接到专用 Exadata 基础结构上的自治 AI 数据库

提示:

For a "try it out" alternative that demonstrates these instructions, run Task 4: Connect to your autonomous DB using SQL Worksheets from Database Actions, SQLCL and SQL Plus from Lab 2: Configure a Development System in the Oracle Autonomous AI Database Dedicated Workshop.
SQLcl (Oracle SQL Developer Command Line) 是 Oracle Database 的命令行界面。它允许您以交互方式或批处理方式执行 SQL 和 PL/SQL。SQLcl 提供内嵌编辑、语句完成和命令撤回,以获得功能丰富的体验,同时还支持您以前编写的 SQL*Plus 脚本。
为了能够将 SQLCl 连接到自治 AI 数据库,运行 SQLCl 的系统必须具有对 Autonomous AI Database 的网络访问权限。这可以通过以下任一方式实现:
  • 通过配置开发系统以访问数据库
  • 通过 VPN(快速连接或 VPN 即服务)或任何 VCN 对等连接(如果计算主机位于另一个 VCN 中)设置正确的网络路由。

您可以将 SQLcl 版本 4.2 或更高版本与 Autonomous AI Database 一起使用。从 oracle.com 下载 SQLcl。

SQLcl 可以使用 Oracle Call Interface (OCI) 或 JDBC 瘦连接来连接到自治 AI 数据库

使用 Oracle Call Interface SQLcl

要使用 Oracle Call Interface 进行连接,请使用 –oci 选项,提供 tnsnames.ora 文件中提供的数据库用户名、密码和数据库服务名称。例如:

sql -oci

SQLcl: Release 19.1 Production on Mon Jan 18 09:28:38 2021

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

Username? (''?) sales_trans@atpc1_low
Password? (**********?) **************
Last Successful login time: Mon Jan 17 2019 15:29:19 -07:00

Connected to:
Oracle Database 19c EE Extreme Perf Release 19.0.0.0.0 - Production
Version 19.9.0.0.0

SQL>

使用 Oracle Call Interface 进行连接时,Oracle Wallet 对 SQLcl 是透明的。

具有 JDBC 瘦连接的 SQLcl

要使用 JDBC Thin 连接进行连接,请先配置 SQLcl 云配置,然后连接到 Autonomous AI Database

  1. 使用 /nolog 选项启动 SQLcl。
    sql /nolog
    
  2. 配置 SQLcl 会话以使用 Oracle Wallet:
    SQL> set cloudconfig directory/client_credentials.zip
    Wallet Password:  **********
  3. 连接到 Autonomous AI Database
    SQL> connect username@servicename
    password

    例如:

    sql /nolog
    
    SQLcl: Release 19.1 Production on Mon Jan 18 09:28:38 2021
    
    Copyright (c) 1982, 2021, Oracle.  All rights reserved.
    
    SQL> set cloudconfig /home/atpc/wallet_ATPC.zip
    Operation is successfully completed.
    Operation is successfully completed.
    Using temp directory:/tmp/oracle_cloud_config3643858537577169472
    
    SQL> connect admin@atpc_medium
    Password? (**********?) ************
    Connected.

有关 tnsnames.ora 中指定的连接类型的更多信息,请参见 Predefined Database Service Names for Autonomous AI Database

有关 SQLcl 的信息,请参见 Oracle SQLcl