Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript node.js exec sql文件_Javascript_Mysql_Database_Node.js - Fatal编程技术网

Javascript node.js exec sql文件

Javascript node.js exec sql文件,javascript,mysql,database,node.js,Javascript,Mysql,Database,Node.js,我有一个sql文件,其中包含: 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); 它有

我有一个sql文件,其中包含:

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);

它有大约275k个插入,有没有一种方法可以将它用于节点?我需要一种方法来创建该表并从节点文件中插入数据,而不需要用户进行任何交互。

使用any连接到您的MySql数据库,从文件(使用)和它读取SQL。

我今天有同样的问题,这里是我的最终解决方案:


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}`);
});

const cp=require('child_process');
cp.exec('mysql-u-p{
如果(错误)抛出错误;
log(`stdout:${stdout}`);
log(`stderr:${stderr}`);
});