Documentation Home
MySQL 9.2 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.8Mb
PDF (A4) - 40.9Mb
Man Pages (TGZ) - 259.7Kb
Man Pages (Zip) - 366.9Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


22.4.3.1 Create, List, and Drop Collections

In MySQL Shell, you can create new collections, get a list of the existing collections in a schema, and remove an existing collection from a schema. Collection names are case-sensitive and each collection name must be unique.

Confirm the Schema

To show the value that is assigned to the schema variable, issue:

mysql-py> db

If the schema value is notSchema:world_x, then set thedb variable by issuing:

mysql-py> \use world_x
Create a Collection

To create a new collection in an existing schema, use thedb object'screateCollection() method. The following example creates a collection calledflags in theworld_x schema.

mysql-py> db.create_collection("flags")

The method returns a collection object.

<Collection:flags>
List Collections

To display all collections in theworld_x schema, use thedb object'sget_collections() method. Collections returned by the server you are currently connected to appear between brackets.

mysql-py> db.get_collections()[    <Collection:countryinfo>,    <Collection:flags>]
Drop a Collection

To drop an existing collection from a schema, use thedb object'sdrop_collection() method. For example, to drop theflags collection from the current schema, issue:

mysql-py> db.drop_collection("flags")

Thedrop_collection() method is also used in MySQL Shell to drop a relational table from a schema.

Related Information