Giter VIP home page Giter VIP logo

altafjava / migrate-mongodb-to-mysql Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 22 KB

This Python script migrates data from a MongoDB database to a MySQL database. It iterates over all collections in the MongoDB database, creates corresponding tables in the MySQL database, and inserts the data.

Python 100.00%
database database-migration migrate migrate-database migration mongodb mongodb-migration mongodb-mysql mysql python sql migrate-mongodb-to-mysql mongodb-to-mysql

migrate-mongodb-to-mysql's Introduction

MongoDB to MySQL Migration Script

This Python script migrates data from a MongoDB database to a MySQL database. It iterates over all collections in the MongoDB database, creates corresponding tables in the MySQL database, and inserts the data.

Prerequisites

Ensure that you have Python installed on your machine. You also need to have MongoDB and MySQL servers running.

Installation

  1. Clone the repository to your local machine.

  2. Navigate to the project directory.

  3. Install the required Python packages:

    pip install pymongo
    pip install pymysql

Configuration

Update the MongoDB and MySQL database credentials in the config.py file:

# Source Database Configuration
mongo_config = {
    'url': 'mongodb://localhost:27017/',
    'db_name': 'sample_guides',
}

# Destination Database Configuration
mysql_config = {
    'host': 'localhost',
    'user': 'root',
    'password': 'mysql',
}

mysql_db_name = 'Test_DB-MySQL' # This will be converted to snake case(test_db_mysql)

Usage

Run the script with the following command:

python migrate.py

The script will connect to the MongoDB database, iterate over all collections, It then connects to the MySQL server, drops the existing database if it exists, and creates a new one. For each MongoDB collection, the script creates a corresponding table and column with snake_case names based on the MongoDB collections' structure, and insert data accordingly. It skips the _id and _class columns during table creation and data insertion based on the configuration settings SKIP_ID_FIELD and SKIP_CLASS_FIELD respectively.

Note

This script assumes that the MongoDB and MySQL servers are running on localhost. If your servers are running on different hosts, update the host information in the database credentials.

migrate-mongodb-to-mysql's People

Contributors

altafjava avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.