With themysqlsh command interface, you invoke the JSON import utility as follows:
mysqlsh user@host:port/mydb -- util importJson <path> [options]ormysqlsh user@host:port/mydb -- util import-json <path> [options]For information on this syntax, seeSection 5.8, “API Command Line Integration”. For the JSON import utility, specify the parameters as follows:
userThe user name for the user account that is used to run the JSON import utility.
hostThe host name for the MySQL server.
portThe port number for MySQL Shell's connection to the MySQL server. The default port for this connection is 33060.
mydbThe name of the target database. When invoking the JSON import utility from the command line, you must specify the target database. You can either specify it in the URI-like connection string, or using an additional
--schemacommand line option.pathThe file path for the file (or FIFO special file) containing the JSON documents to be imported.
optionsThe
--collection,--table, and--tableColumnoptions specify a target collection or a target table and column. The relationships and defaults when the JSON import utility is invoked using themysqlsh command interface are the same as when the corresponding options are used in a MySQL Shell session. If you specify none of these options, the utility defaults to using or creating a target collection with the name of the supplied import file (without the file extension).The
--convertBsonTypesoption converts BSON data types that are represented using extensions to the JSON format. The additional control options for specific BSON data types can also be specified; for a list of these control options and the default type conversions, seeSection 11.2.4, “Conversions for Representations of BSON Data Types”. The--convertBsonOidoption is automatically set on when you specify--convertBsonTypes. When importing data from MongoDB,--convertBsonOidmust be specified if you do not convert the BSON types, because MySQL Server requires the_idvalue to be converted to thevarbinary(32)type.--extractOidTime=can be used to extract the timestamp from thefield_name_idvalue into a separate field.
The following example imports the JSON documents in the fileproducts.json to theproducts collection in themydb database:
mysqlsh user@localhost/mydb -- util importJson products.json --collection=products