PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 23, 2022

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

 February 23, 2022     mysql, node.js, phpmyadmin     No comments   

Issue

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?


Solution

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.



Answered By - andy magoon
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing