Spawn a mysql process to import a database using node
<p>I'm trying to write a node script to automatically import a .sql file. I think I am misunderstanding the way to pass arguments to 'spawn'. Here's what I have:</p>

<pre><code>var spawn    = require('child_process').spawn;
var mysqlimport = spawn('/usr/local/bin/mysql', [
    '-u' + database.user,
    '-p' + database.password,
    '-h' + database.address,
    '--default-character-set=utf8',
    '--comments',
    '&lt;"' + fileName + '"'
]);
mysqlimport
        .stdout
        .pipe(logFile)
        .on('data', function(data) {
           console.log(data); 
        })
        .on('finish', function() {
            console.log('finished')
        })
        .on('error', function(err) {
            console.log(err)
        });
mysqlimport.stderr.on('data', function(data) {
   console.log('stdout: ' + data);
});
mysqlimport.on('close', function(code) {
   console.log('closing code: ' + code);
});
</code></pre>

<p>And I'm getting the error </p>

<pre><code>stdout: ERROR 1049 (42000): Unknown database '&lt;"/users/user/dumps/sqlfile.sql"
</code></pre>

<p>if I don't use the -B flag when exporting, and specify the database name, changing</p>

<pre><code>'&lt;"' + fileName + '"'
</code></pre>

<p>to</p>

<pre><code>databaseName + ' &lt;"' + fileName + '"'
</code></pre>

<p>I get this other error:</p>

<pre><code>stdout: ERROR 1102 (42000): Incorrect database name ' theDatabase &lt; "/users/user/dumps/sqlfile.sql"'
</code></pre>

<p>I know I must be doing something wrong with specifying the argument, but how to fix it? The node documentation around spawning child processes is confusing to me. Thanks for your help!</p>