Overview
This topic describes how to use LOAD DATA in OceanBase Database to write external data into internal tables, and enable direct load when conditions are met (such as using hints like APPEND or direct(...)), or by relying on the tenant-level parameter default_load_mode, to improve the throughput of large-scale data loads.
Syntax
-- FROM FILES()
LOAD DATA /*+ [APPEND | DIRECT(need_sort,max_error,{'full'|'inc'|'inc_replace'})] parallel(N) */ FROM FILES(...) INTO TABLE table_name ...;
-- Server File or Object Storage Single File
LOAD DATA /*+ [APPEND | DIRECT(need_sort,max_error,{'full'|'inc'|'inc_replace'})] parallel(N) */ [REMOTE_OSS] INFILE 'file_name' INTO TABLE table_name ...;
-- Local client files (direct load is not supported)
LOAD DATA LOCAL INFILE 'file_name' INTO TABLE table_name ...;
Classification and syntax relationship of LOAD DATA based on data read location
Path / Syntax |
Data Location |
Typical Application Scenarios |
Syntax and description |
Limitations / Configuration / Additional information |
|---|---|---|---|---|
LOAD DATA FROM FILES(...) |
byFILESThe server-accessible path described in the clause (local directory, object storage URL, HDFS, etc., subject to the manual). |
Single Statement DescriptionLOCATION / FORMAT / PATTERN, suitable for batch scanning and error diagnosis of CSV, ORC, and Parquet files |
ViaFROM FILES(LOCATION = ..., FORMAT = (...), [PATTERN = ...])Declares the set of files to be scanned. The server parses the declaration according to the format and writes it to the target table. It can be used together withLOG ERRORSThe wait_for clause is used for error diagnosis during the import period. |
In a direct load scenario, you canLOAD DATAAdd after the keyword/*+ direct(...) parallel(N) */and other hints |
LOAD DATA ... INFILE 'path'(NoLOCAL) |
Server File System Path Accessible by the OBServer Process | The file has been distributed to the database node or shared storage. This is often used together withsecure_file_priv |
Not specifiedLOCAL, andINFILEWhen the path is on the OBServer, the server directly reads this file (or a set of files matched by the wildcard). |
Configure the path in the secure_file_priv within the allowed range. Modifying this variable typically requires execution through a local Unix Socket connection. |
LOAD DATA REMOTE_OSS INFILE 'oss://...' / 's3://...' |
URL of a single file in the object bucket | Read data from a single file URL in an object bucket | The syntax is written asLOAD DATA REMOTE_OSS INFILE 'oss://...'/'s3://...', and withFROM FILESMediumLOCATIONObject storage URLs also fall under the category of "external large-scale data sources". |
This example usesFROM FILES、INFILE、LOCAL INFILEThree types of organizations; if usingREMOTE_OSS INFILE, you can replace the followingdirect(...)、parallel(N)The application of the WHERE and partitioning clause syntax |
LOAD DATA ... LOCAL INFILE 'path' |
Path on the client where the connection is initiated | The file exists only on the client. The connection must be enabled with--local-infile |
KeywordsLOCALindicates that the file is located on the client's local machine; after being read by the client, it is uploaded to the server for parsing and writing. |
Use when connectingobclient --local-infile(or its equivalent option) to enable local loading; **LOCAL INFILEDirect load is not supported. ** |
Note
For the scope of application, differences, and a more comprehensive description of direct load capabilities between full direct load and incremental direct load, see Overview of Data Import.
For the complete definitions and syntax details of each parameter, see LOAD DATA Syntax (MySQL-compatible mode).
Examples
Full direct load (direct(..., 'full')) is typically used for the initial loading of an empty table or a complete baseline import.
Incremental direct load (direct(..., 'inc') or 'inc_replace') is typically used for append loading based on existing data in the target table.
The two differ in the third parameter of DIRECT(), the target table status, and applicable limitations. For details about the differences, application scenarios, and limitations between full direct load and incremental direct load, see Data import overview.
The following examples focus on full direct load. The syntax for the incremental direct load hint is the same; only the third parameter is changed to 'inc' or 'inc_replace'.
LOAD DATA FROM FILES
Log in to the server where the OBServer node to be connected resides. Prepare the data files to be scanned in the
/home/admindirectory (LOCATIONpoints to a server-accessible path, which can be CSV, ORC, or Parquet files in this directory. This example uses CSV files).Note
The
LOCATIONinFROM FILESmust be a path accessible to the OBServer. It is recommended that the directory and files be within the scope allowed bysecure_file_priv(the same as forLOAD DATA INFILE).Access the server where the OBServer node resides.
[xxx@xxx /home/admin]# ssh admin@10.10.10.1Create the test data file
tbl1.csv(with content identical to the file in the precedingLOAD DATA INFILEexample for easy comparison).[admin@xxx /home/admin]# vi tbl1.csv 1,11 2,22 3,33
Set the import file path.
Set the system variable
secure_file_privto configure the accessible paths for import or export files.Notice
For security reasons, when setting the system variable
secure_file_priv, you must connect to the database via a local Unix Socket to execute the SQL statement that modifies this global variable. For more information, see secure_file_priv.Log in to the server where the OBServer node to be connected resides.
[xxx@xxx /home/admin]# ssh admin@10.10.10.1Execute the following command to connect to the tenant
mysql001via a local Unix Socket connection.obclient -S /home/admin/oceanbase/run/sql.sock -uroot@mysql001 -p******Set the import path to
/home/admin.obclient [(none)]> SET GLOBAL secure_file_priv = "/home/admin"; Query OK, 0 rows affected
After reconnecting to the database, use
LOAD DATA FROM FILESwith the direct load hint to import the data.Create the table
tbl2(the table structure is the same as the full example in the precedingLOAD DATA INFILEsection).obclient [test]> CREATE TABLE tbl2 ( col1 INT PRIMARY KEY, col2 INT ) PARTITION BY RANGE (col1) SUBPARTITION BY RANGE (col1) ( PARTITION p0 VALUES LESS THAN (100) ( SUBPARTITION p0_1 VALUES LESS THAN (50), SUBPARTITION p0_2 VALUES LESS THAN (100) ), PARTITION p1 VALUES LESS THAN (200) ( SUBPARTITION p1_1 VALUES LESS THAN (150), SUBPARTITION p1_2 VALUES LESS THAN (200) ) ); Query OK, 0 rows affectedQuery whether the
tbl2table contains data; it will show the table is empty at this point.obclient [test]> SELECT * FROM tbl2; Empty setUse direct load to scan and import
tbl1.csvinto tabletbl2.If you need to import data using incremental direct load, you can refer to the syntax examples:
obclient [test]> LOAD DATA /*+ direct(true,1024,'inc') parallel(16) */ FROM FILES( LOCATION = '/home/admin', FORMAT = (TYPE = 'CSV', FIELD_DELIMITER = ','), PATTERN = 'tbl1.csv' ) INTO TABLE tbl2;or:
obclient [test]> LOAD DATA /*+ direct(true,1024,'inc_replace') parallel(16) */ FROM FILES( LOCATION = '/home/admin', FORMAT = (TYPE = 'CSV', FIELD_DELIMITER = ','), PATTERN = 'tbl1.csv' ) INTO TABLE tbl2;The subsequent steps will continue with an example of full direct load.
Specify all columns of table
tbl2to import data.obclient [test]> LOAD DATA /*+ direct(true,1024,'full') parallel(16) */ FROM FILES( LOCATION = '/home/admin', FORMAT = (TYPE = 'CSV', FIELD_DELIMITER = ','), PATTERN = 'tbl1.csv' ) INTO TABLE tbl2; Query OK, 3 rows affected Records: 3 Deleted: 0 Skipped: 0 Warnings: 0Specify columns of table
tbl2to import data. For example, specify columnscol1andcol2.obclient [test]> LOAD DATA /*+ direct(true,1024,'full') parallel(16) */ FROM FILES( LOCATION = '/home/admin', FORMAT = (TYPE = 'CSV', FIELD_DELIMITER = ','), PATTERN = 'tbl1.csv' ) INTO TABLE tbl2 (col1,col2); Query OK, 3 rows affected Records: 3 Deleted: 0 Skipped: 0 Warnings: 0Specify a partition of table
tbl2to import data.obclient [test]> LOAD DATA /*+ direct(true,1024,'full') parallel(16) */ FROM FILES( LOCATION = '/home/admin', FORMAT = (TYPE = 'CSV', FIELD_DELIMITER = ','), PATTERN = 'tbl1.csv' ) INTO TABLE tbl2 partition(p0, p1);Specify a subpartition of table
tbl2to import data.obclient [test]> LOAD DATA /*+ direct(true,1024,'full') parallel(16) */ FROM FILES( LOCATION = '/home/admin', FORMAT = (TYPE = 'CSV', FIELD_DELIMITER = ','), PATTERN = 'tbl1.csv' ) INTO TABLE tbl2 partition(p0sp0_1, p1sp1_1);(Optional) Combine with
LOG ERRORSfor error diagnostics during import (only available when the current version supports this clause).obclient [test]> LOAD DATA /*+ direct(true,1024,'full') parallel(16) */ FROM FILES( LOCATION = '/home/admin', FORMAT = (TYPE = 'CSV', FIELD_DELIMITER = ','), PATTERN = 'tbl1.csv' ) INTO TABLE tbl2 LOG ERRORS REJECT LIMIT UNLIMITED;Use the parameter
default_load_modeto import data.Set the value of
default_load_modetoFULL_DIRECT_WRITE.obclient [test]> ALTER SYSTEM SET default_load_mode ='FULL_DIRECT_WRITE';Do not specify hints for the
LOAD DATAstatement.obclient [test]> LOAD DATA FROM FILES( LOCATION = '/home/admin', FORMAT = (TYPE = 'CSV', FIELD_DELIMITER = ','), PATTERN = 'tbl1.csv' ) INTO TABLE tbl2;
Verify whether data has been imported into table
tbl2.obclient [test]> SELECT * FROM tbl2;The query result is as follows:
+------+------+ | col1 | col2 | +------+------+ | 1 | 11 | | 2 | 22 | | 3 | 33 | +------+------+ 3 rows in setThe result shows that data has been imported into table
tbl2.
Log in to the machine where the OBServer node to connect to is located, and prepare
tbl1.csvin the/home/admindirectory (the procedure and data content are the same as for MySQL-compatible mode).Note
The
LOCATIONofFROM FILESis the server-side path; the value and case ofTYPEinFORMATfollow the current tenant mode manual. This example uses the lowercasecsvconsistent with the manual example.Access the machine where the OBServer node is located.
[xxx@xxx /home/admin]# ssh admin@10.10.10.1Create the test data
tbl1.csv.[admin@xxx /home/admin]# vi tbl1.csv 1,11 2,22 3,33
Set the import file path.
Set the system variable
secure_file_privto configure the accessible paths for import or export files.Notice
For security reasons, when setting the system variable
secure_file_priv, you must connect to the database via a local Unix Socket to execute the SQL statement that modifies this global variable. For more information, see secure_file_priv.Log in to the machine where the OBServer node to connect to is located.
[xxx@xxx /home/admin]# ssh admin@10.10.10.1Execute the following command to connect to tenant
oracle001via a local Unix Socket connection.obclient -S /home/admin/oceanbase/run/sql.sock -usys@oracle001 -p******Set the import path to
/home/admin.obclient [(none)]> SET GLOBAL secure_file_priv = "/home/admin"; Query OK, 0 rows affected
After reconnecting to the database, use
LOAD DATA FROM FILESwith the direct load hint to import the data.Create table
tbl2(with the same structure as the Oracle-compatible mode table in the full example above usingLOAD DATA INFILE).obclient [SYS]> CREATE TABLE tbl2 ( col1 INT PRIMARY KEY, col2 INT ) PARTITION BY RANGE (col1) SUBPARTITION BY RANGE (col1) ( PARTITION p0 VALUES LESS THAN (100) ( SUBPARTITION p0_1 VALUES LESS THAN (50), SUBPARTITION p0_2 VALUES LESS THAN (100) ), PARTITION p1 VALUES LESS THAN (200) ( SUBPARTITION p1_1 VALUES LESS THAN (150), SUBPARTITION p1_2 VALUES LESS THAN (200) ) ); Query OK, 0 rows affectedQuery whether table
tbl2contains data; it displays as empty at this point.obclient [SYS]> SELECT * FROM tbl2; Empty setUse direct load to scan and import
tbl1.csvinto tabletbl2.If you need to import data using incremental direct load, you can refer to the syntax examples:
obclient [SYS]> LOAD DATA /*+ direct(true,1024,'inc') parallel(16) */ FROM FILES( LOCATION = '/home/admin', FORMAT = (TYPE = 'csv', FIELD_DELIMITER = ','), PATTERN = 'tbl1.csv' ) INTO TABLE tbl2;or:
obclient [SYS]> LOAD DATA /*+ direct(true,1024,'inc_replace') parallel(16) */ FROM FILES( LOCATION = '/home/admin', FORMAT = (TYPE = 'csv', FIELD_DELIMITER = ','), PATTERN = 'tbl1.csv' ) INTO TABLE tbl2;The subsequent steps will continue with an example of full direct load.
Specify all columns of table
tbl2to import data.obclient [SYS]> LOAD DATA /*+ direct(true,1024,'full') parallel(16) */ FROM FILES( LOCATION = '/home/admin', FORMAT = (TYPE = 'csv', FIELD_DELIMITER = ','), PATTERN = 'tbl1.csv' ) INTO TABLE tbl2; Query OK, 3 rows affected Records: 3 Deleted: 0 Skipped: 0 Warnings: 0Specify columns of table
tbl2to import data. For example, specify columnscol1andcol2.obclient [SYS]> LOAD DATA /*+ direct(true,1024,'full') parallel(16) */ FROM FILES( LOCATION = '/home/admin', FORMAT = (TYPE = 'csv', FIELD_DELIMITER = ','), PATTERN = 'tbl1.csv' ) INTO TABLE tbl2 (col1,col2); Query OK, 3 rows affected Records: 3 Deleted: 0 Skipped: 0 Warnings: 0(Optional) Specify a partition of table
tbl2to import data.obclient [SYS]> LOAD DATA /*+ direct(true,1024,'full') parallel(16) */ FROM FILES( LOCATION = '/home/admin', FORMAT = (TYPE = 'csv', FIELD_DELIMITER = ','), PATTERN = 'tbl1.csv' ) INTO TABLE tbl2 partition(p0, p1);(Optional) Specify a subpartition of table
tbl2to import data.obclient [SYS]> LOAD DATA /*+ direct(true,1024,'full') parallel(16) */ FROM FILES( LOCATION = '/home/admin', FORMAT = (TYPE = 'csv', FIELD_DELIMITER = ','), PATTERN = 'tbl1.csv' ) INTO TABLE tbl2 partition(p0sp0_1, p1sp1_1);Use the parameter
default_load_modeto import data.Set the value of
default_load_modetoFULL_DIRECT_WRITE.obclient [SYS]> ALTER SYSTEM SET default_load_mode ='FULL_DIRECT_WRITE';Do not specify hints for the
LOAD DATAstatement.obclient [SYS]> LOAD DATA FROM FILES( LOCATION = '/home/admin', FORMAT = (TYPE = 'csv', FIELD_DELIMITER = ','), PATTERN = 'tbl1.csv' ) INTO TABLE tbl2;
Verify whether data has been imported into table
tbl2.obclient [SYS]> SELECT * FROM tbl2;The query result is as follows:
+------+------+ | col1 | col2 | +------+------+ | 1 | 11 | | 2 | 22 | | 3 | 33 | +------+------+ 3 rows in setThe result shows that data has been imported into table
tbl2.
LOAD DATA INFILE
Log in to the server where the target OBServer node resides and create test data in the
/home/admindirectory.Note
The
LOAD DATAstatement in OceanBase Database can only load input files located locally on the OBServer node. Therefore, you must copy the file to an OBServer node before importing it.Access the server where the OBServer node resides.
[xxx@xxx /home/admin]# ssh admin@10.10.10.1Create the test data file
tbl1.csv.[admin@xxx /home/admin]# vi tbl1.csv 1,11 2,22 3,33
Set the import file path.
Configure the system variable
secure_file_privto specify the accessible paths for import or export files.Notice
For security reasons, when setting the system variable
secure_file_priv, you must connect to the database via a local Unix Socket to execute the SQL statement that modifies this global variable. For more information, see secure_file_priv.Log in to the server where the target OBServer node resides.
[xxx@xxx /home/admin]# ssh admin@10.10.10.1Execute the following command to connect to the tenant
mysql001via a local Unix Socket.obclient -S /home/admin/oceanbase/run/sql.sock -uroot@mysql001 -p******Set the import path to
/home/admin.obclient [(none)]> SET GLOBAL secure_file_priv = "/home/admin"; Query OK, 0 rows affected
After reconnecting to the database, use the
LOAD /*+ DIRECT */ DATAstatement to import the data.Create table
tbl2.obclient [test]> CREATE TABLE tbl2 ( col1 INT PRIMARY KEY, col2 INT ) PARTITION BY RANGE (col1) SUBPARTITION BY RANGE (col1) ( PARTITION p0 VALUES LESS THAN (100) ( SUBPARTITION p0_1 VALUES LESS THAN (50), SUBPARTITION p0_2 VALUES LESS THAN (100) ), PARTITION p1 VALUES LESS THAN (200) ( SUBPARTITION p1_1 VALUES LESS THAN (150), SUBPARTITION p1_2 VALUES LESS THAN (200) ) ); Query OK, 0 rows affectedQuery whether table
tbl2contains data. The result shows the table is empty.obclient [test]> SELECT * FROM tbl2; Empty setUse direct load to import the data from the
tbl1.csvfile into tabletbl2.If you need to import data using incremental direct load, you can refer to the syntax examples:
obclient [test]> LOAD DATA /*+ direct(true,1024,'inc') parallel(16) */ INFILE '/home/admin/tbl1.csv' INTO TABLE tbl2 FIELDS TERMINATED BY ',';or:
obclient [test]> LOAD DATA /*+ direct(true,1024,'inc_replace') parallel(16) */ INFILE '/home/admin/tbl1.csv' INTO TABLE tbl2 FIELDS TERMINATED BY ',';The following steps will continue with an example of full direct load.
Specify all columns of table
tbl2to import data.obclient [test]> LOAD DATA /*+ direct(true,1024,'full') parallel(16) */ INFILE '/home/admin/tbl1.csv' INTO TABLE tbl2 FIELDS TERMINATED BY ','; Query OK, 3 rows affected Records: 3 Deleted: 0 Skipped: 0 Warnings: 0Specify any specified columns of table
tbl2to import data. For example, specify columnscol1andcol2.obclient [test]> LOAD DATA /*+ direct(true,1024,'full') parallel(16) */ INFILE '/home/admin/tbl1.csv' INTO TABLE tbl2 FIELDS TERMINATED BY ','(col1,col2); Query OK, 3 rows affected Records: 3 Deleted: 0 Skipped: 0 Warnings: 0Specify a partition of table
tbl2to import data.obclient [test]> LOAD DATA /*+ direct(true,1024,'full') parallel(16) */ INFILE '/home/admin/tbl1.csv' INTO TABLE tbl2 partition(p0, p1) FIELDS TERMINATED BY ',';Specify a subpartition of table
tbl2to import data.obclient [test]> LOAD DATA /*+ direct(true,1024,'full') parallel(16) */ INFILE '/home/admin/tbl1.csv' INTO TABLE tbl2 partition(p0sp0_1, p1sp1_1) FIELDS TERMINATED BY ',';Use the parameter
default_load_modeto import data.Set the value of
default_load_modetoFULL_DIRECT_WRITE.obclient [test]> ALTER SYSTEM SET default_load_mode ='FULL_DIRECT_WRITE';Do not specify hints for the
LOAD DATAstatement.obclient [test]> LOAD DATA INFILE '/home/admin/tbl1.csv' INTO TABLE tbl2 FIELDS TERMINATED BY ',';
Verify whether data has been imported into table
tbl2.obclient [test]> SELECT * FROM tbl2;The query result is as follows:
+------+------+ | col1 | col2 | +------+------+ | 1 | 11 | | 2 | 22 | | 3 | 33 | +------+------+ 3 rows in setThe result shows that data has been imported into table
tbl2.
Log in to the server where the OBServer node to be connected resides, and create a test dataset named
tbl1in the/home/admindirectory.Note
The
LOAD DATAstatement in OceanBase Database can only load input files located locally on the OBServer node. Therefore, you must copy the file to an OBServer node before importing it.Access the server where the OBServer node resides.
[xxx@xxx /home/admin]# ssh admin@10.10.10.1Create a test dataset named
tbl1.csv.[admin@xxx /home/admin]# vi tbl1.csv 1,11 2,22 3,33
Set the import file path.
Configure the system variable
secure_file_privto specify the accessible paths for import or export files.Notice
For security reasons, when setting the system variable
secure_file_priv, you must connect to the database via a local Unix Socket to execute the SQL statement that modifies this global variable. For more information, see secure_file_priv.Log in to the server where the OBServer node to be connected resides.
[xxx@xxx /home/admin]# ssh admin@10.10.10.1Execute the following command to connect to the tenant
oracle001via a local Unix Socket connection.obclient -S /home/admin/oceanbase/run/sql.sock -usys@oracle001 -p******Set the import path to
/home/admin.obclient [(none)]> SET GLOBAL secure_file_priv = "/home/admin"; Query OK, 0 rows affected
After reconnecting to the database, use the
LOAD /*+ DIRECT */ DATAstatement to import the data.Create a table named
tbl2.obclient [SYS]> CREATE TABLE tbl2 ( col1 INT PRIMARY KEY, col2 INT ) PARTITION BY RANGE (col1) SUBPARTITION BY RANGE (col1) ( PARTITION p0 VALUES LESS THAN (100) ( SUBPARTITION p0_1 VALUES LESS THAN (50), SUBPARTITION p0_2 VALUES LESS THAN (100) ), PARTITION p1 VALUES LESS THAN (200) ( SUBPARTITION p1_1 VALUES LESS THAN (150), SUBPARTITION p1_2 VALUES LESS THAN (200) ) ); Query OK, 0 rows affectedQuery whether the
tbl2table contains data; it shows the table is empty at this point.obclient [SYS]> SELECT * FROM tbl2; Empty setUse direct load to import the data from the
tbl1.csvfile into thetbl2table.If you need to import data using incremental direct load, you can refer to the following syntax example:
obclient [SYS]> LOAD DATA /*+ direct(true,1024,'inc') parallel(16) */ INFILE '/home/admin/tbl1.csv' INTO TABLE tbl2 FIELDS TERMINATED BY ',';or:
obclient [SYS]> LOAD DATA /*+ direct(true,1024,'inc_replace') parallel(16) */ INFILE '/home/admin/tbl1.csv' INTO TABLE tbl2 FIELDS TERMINATED BY ',';In the following steps, we will continue the explanation using an example of full direct load.
Specify to import all columns from table
tbl2.obclient [SYS]> LOAD DATA /*+ direct(true,1024,'full') parallel(16) */ INFILE '/home/admin/tbl1.csv' INTO TABLE tbl2 FIELDS TERMINATED BY ','; Query OK, 3 rows affected Records: 3 Deleted: 0 Skipped: 0 Warnings: 0Specify any columns from table
tbl2to import. For example, specify columnscol1andcol2.obclient [SYS]> LOAD DATA /*+ direct(true,1024,'full') parallel(16) */ INFILE '/home/admin/tbl1.csv' INTO TABLE tbl2 FIELDS TERMINATED BY ','(col1,col2); Query OK, 3 rows affected Records: 3 Deleted: 0 Skipped: 0 Warnings: 0(Optional) Specify a partition of table
tbl2to import.obclient [SYS]> LOAD DATA /*+ direct(true,1024,'full') parallel(16) */ INFILE '/home/admin/tbl1.csv' INTO TABLE tbl2 partition(p0, p1) FIELDS TERMINATED BY ',';(Optional) Specify a subpartition of table
tbl2to import.obclient [SYS]> LOAD DATA /*+ direct(true,1024,'full') parallel(16) */ INFILE '/home/admin/tbl1.csv' INTO TABLE tbl2 partition(p0sp0_1, p1sp1_1) FIELDS TERMINATED BY ',';Use the parameter
default_load_modeto import data.Set the value of
default_load_modetoFULL_DIRECT_WRITE.obclient [SYS]> ALTER SYSTEM SET default_load_mode ='FULL_DIRECT_WRITE';Do not specify hints for the
LOAD DATAstatement.obclient [SYS]> LOAD DATA INFILE '/home/admin/tbl1.csv' INTO TABLE tbl2 FIELDS TERMINATED BY ',';
Verify whether data has been imported into table
tbl2.obclient [SYS]> SELECT * FROM tbl2;The query result is as follows:
+------+------+ | col1 | col2 | +------+------+ | 1 | 11 | | 2 | 22 | | 3 | 33 | +------+------+ 3 rows in setThe result shows that data has been imported into table
tbl2.
LOAD DATA LOCAL INFILE
Prepare the data file on the client machine where obclient is running (the path is the local client path, do not confuse it with the path on the OBServer). The file content is the same as the example above, still named
tbl1.csv.Note
LOCAL INFILEmeans the client reads a local file and uploads it to the server; the connection command must include--local-infile(or an equivalent option).LOAD DATA LOCAL INFILEdoes not support direct load, so do not add theAPPEND/DIRECT(...)hint.Create a data file on the client (example path
/home/admin/client_csv/tbl1.csv, adjust the directory according to your actual client environment).mkdir -p /home/admin/client_csv vi /home/admin/client_csv/tbl1.csvThe file content is as follows:
1,11 2,22 3,33
Use the local infile capability to connect to the database and enter the target database (example: the
testdatabase under tenantmysql001).obclient --local-infile -h10.10.10.1 -P2881 -uroot@mysql001 -p****** -DtestUse
LOAD DATA LOCAL INFILEto import data (not direct load).Create table
tbl2(the table structure is the same as the full example ofLOAD DATA INFILEabove).obclient [test]> CREATE TABLE tbl2 ( col1 INT PRIMARY KEY, col2 INT ) PARTITION BY RANGE (col1) SUBPARTITION BY RANGE (col1) ( PARTITION p0 VALUES LESS THAN (100) ( SUBPARTITION p0_1 VALUES LESS THAN (50), SUBPARTITION p0_2 VALUES LESS THAN (100) ), PARTITION p1 VALUES LESS THAN (200) ( SUBPARTITION p1_1 VALUES LESS THAN (150), SUBPARTITION p1_2 VALUES LESS THAN (200) ) ); Query OK, 0 rows affectedQuery whether table
tbl2contains data; it shows the table is empty at this time.obclient [test]> SELECT * FROM tbl2; Empty setUse
LOAD DATA LOCAL INFILEto import the clienttbl1.csvinto tabletbl2.Specify all columns of table
tbl2to import data.obclient [test]> LOAD DATA LOCAL INFILE '/home/admin/client_csv/tbl1.csv' INTO TABLE tbl2 FIELDS TERMINATED BY ','; Query OK, 3 rows affected Records: 3 Deleted: 0 Skipped: 0 Warnings: 0Specify columns of table
tbl2to import data. For example, specify columnscol1andcol2.obclient [test]> LOAD DATA LOCAL INFILE '/home/admin/client_csv/tbl1.csv' INTO TABLE tbl2 FIELDS TERMINATED BY ','(col1,col2); Query OK, 3 rows affected Records: 3 Deleted: 0 Skipped: 0 Warnings: 0Specify a partition of table
tbl2to import data.obclient [test]> LOAD DATA LOCAL INFILE '/home/admin/client_csv/tbl1.csv' INTO TABLE tbl2 partition(p0, p1) FIELDS TERMINATED BY ',';Specify a subpartition of table
tbl2to import data.obclient [test]> LOAD DATA LOCAL INFILE '/home/admin/client_csv/tbl1.csv' INTO TABLE tbl2 partition(p0sp0_1, p1sp1_1) FIELDS TERMINATED BY ',';
The
default_load_modedirect load mode is not applicable for theLOCAL INFILEformat; you can directly execute the following statement:obclient [test]> LOAD DATA LOCAL INFILE '/home/admin/client_csv/tbl1.csv' INTO TABLE tbl2 FIELDS TERMINATED BY ',';
Verify whether data has been imported into table
tbl2.obclient [test]> SELECT * FROM tbl2;The query result is as follows:
+------+------+ | col1 | col2 | +------+------+ | 1 | 11 | | 2 | 22 | | 3 | 33 | +------+------+ 3 rows in setThe result shows that data has been imported into table
tbl2.
Prepare
tbl1.csvlocally on the client (for example, at/home/admin/client_csv/tbl1.csv, with the same content as in MySQL-compatible mode).Note
Similar to MySQL-compatible mode, you must use the
--local-infileconnection option. TheINFILEpath must be a local directory on the client and does not support the direct load hint.Create a directory and a file on the client.
mkdir -p /home/admin/client_csv vi /home/admin/client_csv/tbl1.csv1,11 2,22 3,33
Connect to the database using the local infile capability (for example, tenant
oracle001).obclient --local-infile -h10.10.10.1 -P2881 -usys@oracle001 -p******Use
LOAD DATA LOCAL INFILEto import data (non-direct load).Create table
tbl2(identical to the full example ofLOAD DATA INFILEin Oracle-compatible mode above).obclient [SYS]> CREATE TABLE tbl2 ( col1 INT PRIMARY KEY, col2 INT ) PARTITION BY RANGE (col1) SUBPARTITION BY RANGE (col1) ( PARTITION p0 VALUES LESS THAN (100) ( SUBPARTITION p0_1 VALUES LESS THAN (50), SUBPARTITION p0_2 VALUES LESS THAN (100) ), PARTITION p1 VALUES LESS THAN (200) ( SUBPARTITION p1_1 VALUES LESS THAN (150), SUBPARTITION p1_2 VALUES LESS THAN (200) ) ); Query OK, 0 rows affectedQuery whether there is data in table
tbl2; it shows the table is empty.obclient [SYS]> SELECT * FROM tbl2; Empty setUse
LOAD DATA LOCAL INFILEto import the client'stbl1.csvinto tabletbl2.Specify to import all columns of table
tbl2.obclient [SYS]> LOAD DATA LOCAL INFILE '/home/admin/client_csv/tbl1.csv' INTO TABLE tbl2 FIELDS TERMINATED BY ','; Query OK, 3 rows affected Records: 3 Deleted: 0 Skipped: 0 Warnings: 0Specify the columns to import from table
tbl2. For example, specify columnscol1andcol2.obclient [SYS]> LOAD DATA LOCAL INFILE '/home/admin/client_csv/tbl1.csv' INTO TABLE tbl2 FIELDS TERMINATED BY ','(col1,col2); Query OK, 3 rows affected Records: 3 Deleted: 0 Skipped: 0 Warnings: 0(Optional) Specify the partition to import from table
tbl2.obclient [SYS]> LOAD DATA LOCAL INFILE '/home/admin/client_csv/tbl1.csv' INTO TABLE tbl2 partition(p0, p1) FIELDS TERMINATED BY ',';(Optional) Specify the subpartition to import from table
tbl2.obclient [SYS]> LOAD DATA LOCAL INFILE '/home/admin/client_csv/tbl1.csv' INTO TABLE tbl2 partition(p0sp0_1, p1sp1_1) FIELDS TERMINATED BY ',';
The
LOCAL INFILEformat does not support the direct load mode ofdefault_load_mode; you can directly execute the following statement:obclient [SYS]> LOAD DATA LOCAL INFILE '/home/admin/client_csv/tbl1.csv' INTO TABLE tbl2 FIELDS TERMINATED BY ',';
Verify whether data has been imported into table
tbl2.obclient [SYS]> SELECT * FROM tbl2;The query result is as follows:
+------+------+ | col1 | col2 | +------+------+ | 1 | 11 | | 2 | 22 | | 3 | 33 | +------+------+ 3 rows in setThe result shows that data has been imported into table
tbl2.
