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
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