converting database from mysql to mongoDb

后端 未结 13 1368
陌清茗
陌清茗 2020-12-07 10:43

is there any easy way to change the database from mysql to mongoDB ?

or better any one suggest me good tutorial do it

13条回答
  •  悲&欢浪女
    2020-12-07 10:52

    I think one of the easiest ways is to export the MySQL database to JSON and then use mongorestore to import it to a MongoDB database.

    Step 1: Export the MySQL database to JSON

    Load the mysql dump file into a MySQL database if necessary

    Open MySQL Workbench and connect to the MySQL database

    Go to the Schema viewer > Select database > Tables > right-click on the name of the table to export

    Select 'Table Data Export Wizard'

    Set the file format to .json and type in a filename such as tablename.json

    Note: All tables will need to be exported individually

    Step 2: Import the JSON files to a MongoDB using the mongorestore command

    The mongorestore command should be run from the server command line (not the mongo shell)

    Note that you may need to provide the authentication details as well as the --jsonArray option, see the mongorestore docs for more information

    mongoimport -d dbname -u ${MONGO_USERNAME} -p ${MONGO_PASSWORD} --authenticationDatabase admin -c collectionname --jsonArray --file tablename.json
    

    Note: This method will not work if the original MySQL database has BLOBs/binary data.

提交回复
热议问题