在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數據遷移的基本步驟,希望對您有所幫助。