Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mysql = require('mysql');
- var fs = require('fs');
- var database = ""; // Database
- var tables = []; // Tables
- // Credentials
- var connection = mysql.createConnection({
- host: 'localhost',
- user: 'root',
- password: ''
- });
- connection.connect();
- connection.query('use ' + database);
- function go(i) {
- if(i === tables.length - 1) { connection.end(); return; }
- connection.query('select * from ' + tables[i] + ';', function(err, results, fields) {
- if(err) throw err;
- fs.writeFile(tables[i] + '.json', JSON.stringify(results), function (err) {
- if (err) throw err;
- console.log('Saved ' + tables[i]);
- go(++i);
- });
- });
- }
- go(0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement