Aónio
Aónio

Reputation: 579

Read .sql database stored in the disk as a file, in NodeJS

I use nodeJS and npm package mysql to read sql databases from the server. You know, the typical usage:

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'example.org',
  user     : 'bob',
  password : 'secret'
});

//implicit connection and then query
connection.query('SELECT 1', function (error, results, fields) {
  if (error) throw error;
  console.log(results)
});

But now I need to run some tests locally on some virtual machines, and I want to read the data from a sql database stored as a .sql file. This sql file was exported with phpmyadmin

enter image description here

How can I read from a sql database whose data is stored in the disk as a .sql file, said file exported via phpmyadmin?

Upvotes: 1

Views: 721

Answers (1)

andy magoon
andy magoon

Reputation: 2929

You cannot use the file as a database. (Although that would be a cool project for somebody to create.)

The .sql file is just an export which contains actual sql statements one after another, which can be used to re-create a database by "importing".

My recommendation is to install mysql-server locally, import what you have, and connect to localhost 3306.

Upvotes: 2

Related Questions