I am trying to import the sql file in express js. i try the following codes but it is not work while using mssql and fs module
fs.readFile(__dirname +'/database.sql', function (err, sqlFile) {
if(err) { throw err; }
connection.query(sqlFile, function(err, results) {
if (err) throw err;
console.log(results);
});
console.log(sqlFile);
});
It is not working it says ER_EMPTY_QUERY: Query was empty
While i try execsql module.
var execsql = require('execsql'),
dbConfig = {
host: 'localhost',
user: 'root',
password: 'root'
},
sql = 'use db_cam;',
sqlFile = __dirname + '/db.sql';
execsql.config(dbConfig) .exec(sql) .execFile(sqlFile, function(err, results){ console.log(results); }).end();
It returns ER_ACCESS_DENIED_ERROR