NodeJS/mySQL - ER_ACCESS_DENIED_ERROR Access denied for user 'root'@'localhost' (using password: YES)

前端 未结 29 4270
北恋
北恋 2020-12-13 13:26

I am attempting to connect to mySQL through a NodeJS file, but I receive the following error:

{ Error: ER_ACCESS_DENIED_ERROR: Access denied for user \'root\         


        
29条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 13:37

    The problem is not with the mysql user authentication. It just that you have to grant your node application to access mysql db. I was facing the same issue earlier.I added the port number on which my node application is running.And its working perfectly fine now.

    Also user:"root" was written as username:"root" . Be careful with the spellings.

    const mysqlConnection = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "Pass@123",
    database: "employees",
    port:"3000",
    multipleStatements: true
    

    });

    I am using mysql version "mysql": "^2.18.1".

提交回复
热议问题