I’ve dropped my SEND encoding into MySQL tables for now so I can drive my SEND file creation from data right “from the horses mouth” so to speak – a business layer which interprets the regulatory framework exactly as expressed in the SENDIG in an iterative manner. I’m now ready to consume that data from within my Node.js project. There are plenty of sites offering sample code to do this and the prevailing choice of library seems to be the intuitively titled node-mysql. The example tutorial I used was this one.
But I ran in to a few snags right off the bat, and was unable to connect to the database.
Echoing the error to the console window I was seeing the following:
Access denied for user ''@'localhost'
So I turned to the command line. I’m working on windows and don’t have MySQL in my path (and too lazy to add it) so the command looked like this:
"C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin\mysql.exe" -u myuser -p******
Same error occurred. Looking at the users in MySQL workbench, myuser is definitely there with all the right grants, so what’s going on?
Stack Overflow is the ultimate resource for developers and sure enough this link came up. It’s not the most upvoted comment which bailed me out, but this one:
I was brought here by a different problem. Whenever I tried to login, i got that message because instead of authenticating correctly I logged in as anonymous user. The solution to my problem was:
To see which user you are, and whose permissions you have:
select user(), current_user();
To delete the pesky anonymous user:
drop user ''@'localhost';
Basically even though I was trying to specify myuser, it was always logging me in as an anonymous user, which quite rightly has very few privileges. What are those anonymous users even for? Seems like pretty bad practice to me. In short, deleting the anonymous user(s) from my database (he was in there several times) worked and the code examples just worked. Now I’m able to crack on with the data I need delivered directly into my Node app.