0

I have a sql file that contains:

DROP TABLE IF EXISTS aodb;
CREATE TABLE aodb (lowid INT, highid INT, lowql INT, highql INT, name VARCHAR(150), icon INT);
INSERT INTO aodb VALUES (275403, 275403, 1, 1, '"A History of Rubi-Ka" by Prof. Arthur B. Diggins', 136331);

It has about 275k inserts, is there a way I can use it with node? I need a way to create that table and insert the data from inside a node file w/o any kind of interaction from the user.

2 Answers 2

2

Connect to your MySql database with any Node.js MySql client, read SQL from the file (using fs module) and execute it.

Sign up to request clarification or add additional context in comments.

Comments

0

I have the same question today, here is my final solution:


const cp = require('child_process');

cp.exec('mysql -u<your_user> -p<your_password> < your_file.sql', (error, stdout, stderr) => {
    if (error) throw error;
    console.log(`stdout: ${stdout}`);
    console.log(`stderr: ${stderr}`);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.