1

I'm using node.js with mysql database.

I'm using the config like this:

var mysql = require('mysql');
var client = mysql.createConnection({
     host: 'localhost',
     user: 'root',
     password: 'java1234',
     port: '3306',
     database: 'sample'
});

and then I get these error messages:

Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: NO) at Handshake.Sequence._packetToError (C:\node\test11_users\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14) at Handshake.ErrorPacket (C:\node\test11_users\node_modules\mysql\lib\protocol\sequences\Handshake.js:124:18) at Protocol._parsePacket (C:\node\test11_users\node_modules\mysql\lib\protocol\Protocol.js:278:23) at Parser.write (C:\node\test11_users\node_modules\mysql\lib\protocol\Parser.js:76:12) at Protocol.write (C:\node\test11_users\node_modules\mysql\lib\protocol\Protocol.js:38:16) at Socket. (C:\node\test11_users\node_modules\mysql\lib\Connection.js:91:28) at Socket. (C:\node\test11_users\node_modules\mysql\lib\Connection.js:502:10) at emitOne (events.js:116:13) at Socket.emit (events.js:211:7) at addChunk (_stream_readable.js:263:12) -------------------- at Protocol._enqueue (C:\node\test11_users\node_modules\mysql\lib\protocol\Protocol.js:144:48) at Protocol.handshake (C:\node\test11_users\node_modules\mysql\lib\protocol\Protocol.js:51:23) at Connection.connect (C:\node\test11_users\node_modules\mysql\lib\Connection.js:118:18) at Connection._implyConnect (C:\node\test11_users\node_modules\mysql\lib\Connection.js:453:10) at Connection.query (C:\node\test11_users\node_modules\mysql\lib\Connection.js:198:8) at C:\node\test11_users\routes\users.js:26:10 at Layer.handle [as handle_request] (C:\node\test11_users\node_modules\express\lib\router\layer.js:95:5) at next (C:\node\test11_users\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (C:\node\test11_users\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (C:\node\test11_users\node_modules\express\lib\router\layer.js:95:5)

but I can't solve this problem. thanks for your explain easily.

7
  • 1
    It basically means your credentials are not correct. Are you able to access mySQL outside? Commented Oct 15, 2018 at 6:56
  • How can I access mysql outside? Do you mean Workbench? Commented Oct 15, 2018 at 7:08
  • yes or phpadmin anything will do. try logging in with the creds above. Commented Oct 15, 2018 at 7:09
  • I can access mysql with Workbench surly. but only node.js not working Commented Oct 15, 2018 at 7:10
  • go to users and privileges page in work bench and check the configuration for root over there. Commented Oct 15, 2018 at 7:17

1 Answer 1

-1

Remove port from connection options and try

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : 'java1234',
  database : 'sample'
});

connection.connect();

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.