Overview
Excel is a widely used spreadsheet and data visualization tool. You can directly connect to OceanBase Database using the OceanBase ODBC driver and perform efficient data queries and analysis.
This topic describes how to connect to OceanBase Database using ODBC data sources in WPS Office Excel and Microsoft Excel.
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).
- Installed The OceanBase ODBC driver (version ≥ 2.0.9.5hotfix). You can contact Technical Support for the driver.
- Deployed OceanBase Database and created an Oracle/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 ODP connections, use the ODP address. For direct connections, use the OBServer IP address.$port: the connection port. For ODP connections, the default port is2883. For direct connections, the default port is2881.$database_name: the database name.Notice
The user connecting 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 ODP connections, the format isUser@Tenant#ClusterorCluster:Tenant:User. For direct connections, 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 describes how to configure the ODBC DSN for an Oracle mode user tenant of OceanBase Database. You can configure the ODBC DSN for a MySQL mode user tenant in the same way.
- Open the ODBC Data Source Administrator.
- On the System DSN or User DSN tab, click Add.
- Select OceanBase ODBC 2.0 Driver.
- Configure the connection parameters:
- Data Source Name: specify the DSN name (for example,
OBORACLE). - Description: (Optional) specify a description.
- Server name: the IP address of the OceanBase server (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: specify the DSN name (for example,
Step 3: Connect to OceanBase Database
WPS Office Excel
- Open WPS Office Excel.
- Choose 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 input an SQL statement for querying.
- Preview and complete the data import.
Microsoft Excel
Open Microsoft Excel.
Choose Data > Get Data > From Other Sources > From ODBC.
Select the configured ODBC DSN (for example,
OBORACLE).In the advanced options, you can directly input 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.
