0

I’m trying to work with SQL to create a database and connect it to a Javascript document (all local for now). I have the following code in Javascript:

var mysql = require('mysql');


var con = mysql.createConnection({
  host: "localhost",
  user: "name",
  password: "123"
});

con.connect(function(err) {
  if (err) throw err;
  console.log("Connected!");
  con.query("CREATE DATABASE mydb", function (err, result) {
    if (err) throw err;
    console.log("Database created");
  });
});

In my Javacript file, which is saved under the SQLITE folder, on my hard drive. I went into command prompt, hoping to create a database. However, when I type in “node db_connection.js” (once connected to the SQLITE folder as my directory, the computer alternates between doing nothing and offering another chance for input on the next line, maintaining directory, or it returns the following error message:

C:\Users\julia\OneDrive\Documents\sqlite>node db_connection.js
C:\Users\julia\OneDrive\Documents\sqlite\db_connection.js:12
  if (err) throw err;
           ^

Error: connect ECONNREFUSED 127.0.0.1:3306
    at Object._errnoException (util.js:992:11)
    at _exceptionWithHostPort (util.js:1014:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
    --------------------
    at Protocol._enqueue (C:\Users\julia\node_modules\mysql\lib\protocol\Protocol.js:144:48)
    at Protocol.handshake (C:\Users\julia\node_modules\mysql\lib\protocol\Protocol.js:51:23)
    at Connection.connect (C:\Users\julia\node_modules\mysql\lib\Connection.js:118:18)
    at Object.<anonymous> (C:\Users\julia\OneDrive\Documents\sqlite\db_connection.js:11:5)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)

I disabled Windows Firewall, and created a new document, neither of which fixed the problem. Any help you could provide for the matter would be greatly appreciated. Thank you, -J

piGirl
  • 1
  • 1
  • Node.js? - Your talking about SQLite but your code uses MySQL - These are different database platforms ... – Alex K. Sep 07 '18 at 14:32
  • Alex K.---> How do I fix that? (I don't have too much experience with this program; I generally work in HTML) – piGirl Sep 09 '18 at 15:33

0 Answers0