OBLOADER V4.3.5 and later versions support importing database objects to multiple databases or schemas in a single import task, while maintaining compatibility with the original single-database import behavior.
Overview
The import feature for multiple databases allows you to specify the range of objects to be imported using an object expression in the format <schema.object>, such as test.table1, test1.*, *.*, test[0-9].tbl, test*.table, or test?.tbl.
When you use the multi-database import feature, the system will print an import list and ask for confirmation. You can use the -y option to skip the confirmation.
Implementation
Single-database mode
If the object parameters such as --table and --view do not contain a specific database or schema (i.e., they do not contain a period (.)), the system operates in single-database mode, maintaining its original behavior.
Multi-database mode
If any object parameter value contains a specific database or schema (i.e., it contains a period (.)), the system switches to multi-database mode. Examples include test.table1, test1.*, or *.*.
In multi-database mode, a single multi-database import command is split into multiple single-database import subtasks. Here's how it works:
The system parses the object parameters such as
--tableand--view, and distributes the<schema.object>expressions to corresponding subtasks for each database or schema, specifying the import range for each.If an object does not contain a specific database or schema (e.g.,
tbl2in--table 'db1.tbl1, tbl2' -D 'db2'), the system uses the default database specified by-Dfor that object, while keeping other options unchanged.
In multi-database mode, importing objects to different databases or schemas is equivalent to executing multiple single-database import tasks. Here's an example:
obloader -D test --table 'test1.tbl1,test2.tbl2' ...
-> obloader -D test1 --table tbl1 ...
-> obloader -D test2 --table tbl2 ...
obloader -D test --table 'tbl1,test2.tbl2' ...
-> obloader -D test --table tbl1 ...
-> obloader -D test2 --table tbl2 ...
By default, the import directory structure matches the dataset generated by multi-database export, which is organized by database/schema levels. Based on the source and characteristics of the directory structure of the data to be imported, multi-database import can be categorized into the following three scenarios.
Notice
If the database or schema name contains characters such as [, {, or other wildcard control characters, you need to escape these characters to successfully import the data.
The directory structure to be imported is generated by OBDUMPER.
Assume that you specify
-f ./outputswhen you use OBLOADER for multi-database import, and theoutputsdirectory has the following structure:./outputs/ └── data ├── test │ ├── TABLE │ │ ├── sample_tbl1.csv │ │ ├── sample_tbl1-schema.sql │ │ ├── sample_tbl2.csv │ │ └── sample_tbl2-schema.sql │ └── VIEW │ ├── sample_tbl1_view-schema.sql │ └── sample_tbl2_view-schema.sql └── test1 ├── TABLE │ ├── sample_tbl1.csv │ ├── sample_tbl1-schema.sql │ ├── sample_tbl2.csv │ └── sample_tbl2-schema.sql └── VIEW ├── sample_tbl1_view-schema.sql └── sample_tbl2_view-schema.sql 7 directories, 12 filesIn this case, if you specify the following parameters for multi-database import:
--table 'test*.*' --view 'test*.*' -f ./outputs, the system will locate the data in the corresponding database/schema directories based on the<schema.object>expressions and import it.Assume that the target OceanBase Database has three databases named
test,test1, andtest2. In this case, multi-database import will import the objects in the./outputs/data/testdirectory to thetestdatabase, and the objects in the./outputs/data/test1directory to thetest1database. Thetest2database does not have a corresponding directory structure, so no data will be imported to it.The directory structure to be imported is not generated by OBDUMPER.
This directory structure is created by the user or another program. If you perform multi-database import in this directory structure, the behavior is equivalent to executing multiple single-database import tasks in the same directory.
Assume that you specify
--table 'test*.*' --view 'test*.*' -f ./outputs, and theoutputsdirectory has the following structure:./outputs/ ├── sample_tbl1.csv ├── sample_tbl1-schema.sql ├── sample_tbl2.csv └── sample_tbl2-schema.sql 0 directories, 4 filesAssume that the target OceanBase Database has three databases named
test,test1, andtest2. Since the import program cannot identify the database names from the files, multi-database import will import all objects in the./outputsdirectory to thetest,test1, andtest2databases in the target OceanBase Database.The directory structure to be imported is not generated by OBDUMPER, and the
--file-regular-expressionparameter is used.The
--file-regular-expressionparameter allows you to use regular expressions to define rules for matching specific files for import. It also allows you to use capture groups to extract schema and table names from the file names.Assume that you specify
--table 'test*.*' --file-regular-expression '(?<schema>[a-z0-9]+)\.(?<table>[a-z_0-9]+)\.csv' -f ./outputsfor import, and theoutputsdirectory has the following structure:./outputs/ ├── test1.sample_tbl2.csv └── test.sample_tbl1.csv 0 directories, 2 filesAssume that the target OceanBase Database has three databases named
test,test1, andtest2. In this case, multi-database import will import the./outputs/test1.sample_tbl2.csvfile to thetest1database, and the./outputs/test.sample_tbl1.csvfile to thetestdatabase. Thetest2database does not have a corresponding directory structure, so no data will be imported to it.
Examples
Example 1: Single-database export + single-database import (original behavior)
Import the
testdatabase exported from/outputsback to thetestdatabase../obloader -h xxx.xxx.xxx.xxx -P 2883 -u test@mysql#cluster_a -p ****** -D test --csv --table '*' -f /outputsImport the
testdatabase exported from/outputsto another database namedtest1../obloader -h xxx.xxx.xxx.xxx -P 2883 -u test@mysql#cluster_a -p ****** -D test1 --csv --table '*' -f /outputs
Example 2: Multi-database export + multi-database import (import each database as is)
Before you proceed, you run the following command to export the test1, test2, and test3 databases.
./obdumper -h xxx.xxx.xxx.xxx -P 2883 -u test@mysql#cluster_a -p ****** --csv --table 'test[1-3].*' -f /outputs
Notice
When you export multiple databases, you can only import the corresponding database files to the databases with the same names. For example, the test2 database file can be imported only to the test2 database. This is the default behavior of multi-database import.
Import all databases
Method 1
./obloader -h xxx.xxx.xxx.xxx -P 2883 -u test@mysql#cluster_a -p ****** --csv --table 'test[1-3].*' -f /outputsMethod 2
./obloader -h xxx.xxx.xxx.xxx -P 2883 -u test@mysql#cluster_a -p ****** --csv --table '*.*' -f /outputsMethod 3
./obloader -h xxx.xxx.xxx.xxx -P 2883 -u test@mysql#cluster_a -p ****** --csv --table 'test1.*, test2.*, test3.*' -f /outputs
Import only the
test1andtest2databasesMethod 1
./obloader -h xxx.xxx.xxx.xxx -P 2883 -u test@mysql#cluster_a -p ****** --csv --table 'test[1-2].*' -f /outputsMethod 2
./obloader -h xxx.xxx.xxx.xxx -P 2883 -u test@mysql#cluster_a -p ****** --csv --table 'test1.*,test2.*' -f /outputsMethod 3
./obloader -h xxx.xxx.xxx.xxx -P 2883 -u test@mysql#cluster_a -p ****** --csv --table 'test1.*' --table 'test2.*' -f /outputs
Example 3: Multi-database export + single-database import (select one database for import)
After you export multiple databases, you can import them to the same database by using the -f parameter to specify the input directory.
Before you proceed, you run the following command to export the test1, test2, and test3 databases.
./obdumper -h xxx.xxx.xxx.xxx -P 2883 -u test@mysql#cluster_a -p ****** --csv --table 'test[1-3].*' -f /outputs
Import the
test2database exported from/outputsto thetest2database. This scenario executes the multi-database import logic. Thetest2.*parameter specifies the database, and the-D testparameter is ignored../obloader -h xxx.xxx.xxx.xxx -P 2883 -u test@mysql#cluster_a -p ****** -D test --csv --table 'test2.*' -f /outputsImport the
test1subdirectory as a single database to the target databasetest. This scenario executes the single-database import logic../obloader -h xxx.xxx.xxx.xxx -P 2883 -u test@mysql#cluster_a -p ****** -D test --csv --table '*' -f /outputs/data/test1Point to the root directory and use
--table '*'to import thetest1,test2, andtest3databases as a single database to thetestdatabase. This scenario executes the original single-database import logic../obloader -h xxx.xxx.xxx.xxx -P 2883 -u test@mysql#cluster_a -p ****** -D test --csv --table '*' -f /outputsNote
When you import multiple databases to a single database, the original single-database import logic is executed. The input directory is specified by using the
-fparameter.
Example 4: Tenant-level import (import each database as is)
Import all objects of all databases, including definitions and data.
./obloader -h xxx.xxx.xxx.xxx -P 2883 -u test@mysql#cluster_a -p ****** --table '*.*' --ddl --csv --all -f /outputs