在CentOS上进行MongoDB数据迁移的步骤如下:
mongo
命令关闭MongoDB服务,然后使用mongod --shutdown --dbpath
命令关闭MongoDB服务。mongodump
命令备份源数据库。例如,备份名为source_db
的数据库,需要迁移的集合名为source_collection
,运行以下命令:mongodump --host source_host --port source_port --db source_db --collection source_collection --out backup_directory
其中,source_host
和source_port
分别是源MongoDB实例的主机名和端口号,backup_directory
是备份数据的输出目录。
/etc/profile
中配置MongoDB的路径。mongorestore
命令将备份数据导入到目标数据库。例如,将备份数据导入到名为target_db
的数据库和名为target_collection
的集合中,运行以下命令:mongorestore --host target_host --port target_port --db target_db --collection target_collection backup_directory/source_db/source_collection.bson
其中,target_host
和target_port
分别是目标MongoDB实例的主机名和端口号。
以上就是在CentOS上进行MongoDB数据迁移的基本步骤,希望对您有所帮助。