Need assistance with accessing mysql database using node.js

后端 未结 6 1619
清酒与你
清酒与你 2021-01-06 03:08

I am trying to run a simple node sample for access a mysql db and am getting the following error-Error: ER_ACCESS_DENIED_ERROR: Access denied for user \'root\'@\'ubuntu.loca

6条回答
  •  离开以前
    2021-01-06 03:48

    I was getting the exact same issue. I was not able to connect via the mysql module in nodejs, but was able to connect via the mysql client in the terminal (mysql -u root -p1111 -h localhost mydb)

    It turns out, the mysql module converts "localhost" to 127.0.0.1. This would not work via the (mysql -u root -p1111 -h 127.0.0.1 mydb). See Issue 734

    So I had to set a password for 127.0.0.1 in MySQL and it solved the problem.

    Instructions

    Connect to mysql via the console:

    mysql -u root -p mysql
    

    And Run

    SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('Add-Your_password-here');
    

    Source

提交回复
热议问题