A Node.js script to migrate MySQL data to MongoDB, mapping MySQL tables to MongoDB collections.
Will allow migrations from and to remote sites.
Open terminal in your working directory and .....
Method I
- Clone project
git clone https://github.com/dannysofftie/mysql-mongo-migrate.git
- Install dependencies
npm install
- Make it happen 😉
npm run migrate
Method II
- Install package globally
npm i -g mysql-mongo-migrate
- Run command
$> mysql-mongo-migrate
Issues might occur if you don't have authentication set up in your MongoDB database, as read and write roles are required when inserting bulk data into MongoDB.
Follow below steps to enable authentication in your server:
This set up is for Linux distros only. Check online for your operating system if not a linux distro.
-
Uncomment the following code block at the bottom of
/etc/mongo.conf
$> sudo vi /etc/mongo.conf # security: # authorization: enabled
-
Login to your server and create a user for your database.
$> mongo > use databaseName > db.createUser({user: "username", pwd: "password", role: [{roles: "readWrite", db: "databaseName"}]})
Replace with your preferred credentials. You will use them to do migration in the other steps
-
Exit the mongo shell and restart mongod service.
$> sudo service restart mongo
You should be ready to migrate your data now.
- Retrieve MySQL database models and data
- Generate Mongoose schemas in Typescript
- Dump MySQL data into MongoDB