0

i got the above error my code was like this

var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "username",
password: "password",
socketPath: "/Applications/MAMP/tmp/mysql/mysql.sock"
});
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");
});
});

con.end();

i tried to do as they explain in the below link but i did not know how to find my socket path?

enter link description here

Anu
  • 9
  • 4
  • In the link you shared, I believe they tell you how to find the socket path: *In MAMP, you go to http://localhost:8888/MAMP, and you find:...*. That may or may not be your issue. Make sure everything else is correct such as that your server is setup to listen on the default MySQL port. – lurker Apr 14 '20 at 19:59
  • @luker the link display 404 not found error – Anu Apr 14 '20 at 20:06
  • Are you running [MAMP](https://en.wikipedia.org/wiki/MAMP)? The question you linked pertains to a setup that uses MAMP. – lurker Apr 14 '20 at 20:10
  • no i am not i simply want to connect my sql by java script code – Anu Apr 14 '20 at 21:12
  • Then that link's suggestion won't help you and you need to remove the `socketPath` line. As I mentioned previously, verify that your server is running and active on the default MySQL port and that you have the password and username correct. – lurker Apr 14 '20 at 22:02

0 Answers0