An npm project. Node.js Execute your *.sql files which contain multiple sql statements.
-
Make sure you have
execsql
installed globallynpm install -g execsql
-
Configure your db access for the first time. Usage:
execsql -c host [port] user password
.# default port is 3306 execsql -c "localhost" "root" "root" # when using a custom port like 4242 execsql -c "localhost" 4242 "root" "root"
-
Execute a bunch of sql statements
execsql "use db_cam; delete from admin;"
-
Execute a
.sql
fileexecsql -f ./db.sql
-
Make sure you have
execsql
installed locallynpm install execsql
-
Require and use
var execsql = require('execsql'), dbConfig = { host: 'localhost', port: 3306, // optional, default is 3306 user: 'root', password: 'root' }, sql = 'use db_cam;', sqlFile = __dirname + '/db.sql'; execsql.config(dbConfig) .exec(sql) .execFile(sqlFile, function (err, results) { if (err) throw err; console.log(results); }) .end();