0

I have installed mysql on my computer though it showed some packages may not be installed (during installation) but its showing unexpected erros when I'm trying to execute with Node JS.

I have tried both global and local method of installing mysql using 'npm' and tried in every directory but still my code is not working properly .

var mysql = require('mysql');

var con = mysql.createConnection({
host: "localhost",
user: "yourusername",
password: "yourpassword",
database: "mydb"
  });

con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
 var sql = "INSERT INTO customers (name, address) VALUES ?";
 var values = [
['John', 'Highway 71'],
['Peter', 'Lowstreet 4'],
['Amy', 'Apple st 652'],
['Hannah', 'Mountain 21'],
['Michael', 'Valley 345'],
['Sandy', 'Ocean blvd 2'],
['Betty', 'Green Grass 1'],
['Richard', 'Sky st 331'],
['Susan', 'One way 98'],
['Vicky', 'Yellow Garden 2'],
['Ben', 'Park Lane 38'],
['William', 'Central st 954'],
['Chuck', 'Main Road 989'],
['Viola', 'Sideway 1633']
  ];
con.query(sql, [values], function (err, result) {
if (err) throw err;
console.log("Number of records inserted: " + result.affectedRows);
 });
 });

I have installed properly everything from Node to Mysql and it is showing error in try catch block .Please suggest something

4
  • That code is working correctly on my environment, I see 14 records inserted. So I'd try connecting via the command line mysql app and see if you can connect. Commented Feb 5, 2019 at 8:06
  • "it is showing error". Which are ? Commented Feb 5, 2019 at 9:11
  • To be able to debug the issue, maybe consider adding; connection.connect(function(err) { console.log(err.code); // 'ECONNREFUSED' console.log(err.fatal); // true }); Commented Feb 5, 2019 at 9:26
  • C:\Users\luckyy\Desktop\Node JS\node_modules\mysql\lib\protocol\Parser.js:80 throw err; // Rethrow non-MySQL errors ^ Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client at Handshake.Sequence._packetToError (C:\Users\luckyy\Desktop\Node JS\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14) at Handshake.ErrorPacket Please Note : I am running it in normal cmd of windows and Im running in Node JS directory ..please help Commented Feb 6, 2019 at 10:11

1 Answer 1

0

mysql and node js connection and configuration

reference url: Access MySQL server in private ec2 instance in nodejs

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.