Overview
Excel is a widely used spreadsheet and data visualization tool. You can directly connect to OceanBase Database through the OceanBase ODBC driver to efficiently query and analyze data.
This topic describes how to connect to OceanBase Database in WPS Office Excel and Microsoft Excel by using an ODBC data source.
Version compatibility
- OceanBase Database version: ≥ V4.2.5 BP2.
Prerequisites
Before you connect to OceanBase Database in Excel, make sure that:
- You have installed Excel (WPS Office Excel or Microsoft Excel).
- You have installed the OceanBase ODBC driver (version ≥ 2.0.9.5hotfix). The driver is not publicly available. Contact OceanBase Technical Support for more information.
- You have deployed OceanBase Database and created an Oracle or MySQL mode user tenant. For more information about how to create a user tenant, see Create a tenant.
Procedure
Step 1: Obtain the database connection string
Obtain the connection string from the OceanBase Database deployment engineer. For example:
obclient -h$host -P$port -u$user_name -p$password -D$database_name
Parameter description:
$host: the connection IP address. For an ODP connection, use the ODP IP address. For a direct connection, use the OBServer IP address.$port: the connection port. For an ODP connection, the default value is2883. For a direct connection, the default value is2881.$database_name: the database name.Notice
The user who connects to the tenant must have the
CREATE,INSERT,DROP, andSELECTprivileges on the database. For more information about user privileges, see Privilege types in MySQL mode.$user_name: the connection account. For an ODP connection, the format isUser@Tenant#ClusterorCluster:Tenant:User. For a direct connection, the format isUser@Tenant.$password: the account password.
For more information about the connection string, see Connect to an OceanBase tenant by using OBClient.
Here is an example:
obclient -h$host -P2881 -u$user_name -p$password -D$database_name
Step 2: Configure the ODBC DSN
This topic uses an OceanBase Database user tenant in Oracle mode as an example to configure the ODBC DSN. The procedure for an OceanBase Database user tenant in MySQL mode is similar.
- Open the system ODBC Data Source Administrator.
- In the System DSN or User DSN tab, click Add.
- Select the OceanBase ODBC 2.0 Driver driver.
- Configure the connection parameters:
- Data Source Name: enter the DSN name (for example,
OBORACLE). - Description: optional description.
- Server name: the OceanBase Database server address (corresponding to
$host). - Port: the port number (corresponding to
$port). - Database: the database name (corresponding to
$database_name). - User name: the username (corresponding to
$user_name). - Password: the password (corresponding to
$password).
- Data Source Name: enter the DSN name (for example,
Step 3: Connect to OceanBase Database
WPS Office Excel
- Open WPS Office Excel.
- Navigate to Data → Get Data → Import Data → ODBC DSN.
- In the data source selection dialog box, select the configured ODBC DSN (for example,
OBORACLE). - Select the tables and fields to import.
- In the data filtering and sorting step, you can directly enter an SQL statement to query.
- Preview and complete the data import.
Microsoft Excel
Open Microsoft Excel.
Navigate to Data → Get Data → From Other Sources → From ODBC.
Select the configured ODBC DSN (for example,
OBORACLE).In the advanced options, you can directly enter an SQL statement, for example:
SELECT * FROM T1;Click OK and load the data.
FAQ
How to fix garbled characters when connecting to OceanBase Database? Cause: Outdated ODBC driver version Solution: Upgrade to OceanBase ODBC 2.0.9.5 hotfix or later.
