0

I have been trying since yesterday and somehow it's not working. i dont know where am I going wrong with this.

here's the code in connections.js

module.exports.connections = {
    mysql: {
         adapter: 'sails-mysql',
         host: 'localhost',     
         user: 'root', //optional
         password: 'root', //optional
         database: 'mysql' //optional
       }
}

and here's the code in models.js

module.exports.models = {
       connection:'mysql',
       migrate:'alter'
    }

could you guys tell me what's wrong here? and what's the reason for this error?

Here's the detailed error

error: A hook (`orm`) failed to load!
error: Error (E_UNKNOWN) :: Encountered an unexpected error
: Could not connect to MySQL:
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)
    at afterwards (/Users/faraz/code-playground/sailsapi/node_modules/sails-mysql/lib/connections/spawn.js:72:13)
    at /Users/faraz/code-playground/sailsapi/node_modules/sails-mysql/lib/connections/spawn.js:40:7
    at Handshake.onConnect [as _callback] (/Users/faraz/code-playground/sailsapi/node_modules/sails-mysql/node_modules/mysql/lib/Pool.js:54:9)

just wanted to show you the main page when I start mamp. i think there's something wrong there because it actually opens on http://localhost:8888/MAMP/?language=English but config shows port as 3306 could that be the problem??

here's a screenshot enter image description here

faraz
  • 2,603
  • 12
  • 39
  • 61
  • The error is pretty straight forward. You are using the wrong credentials for your database. Have you tried to access it (with a client program) with that user and password? If it is a fresh MySql install it usually is user 'root' password '' (blank (empty)) – Jorge Campos Mar 27 '18 at 05:57
  • I tried with blank password too, but still same error. i added a screenshot above and explained a bit more, so maybe that could be the problem? – faraz Mar 27 '18 at 06:16
  • Maybe, try to use this `host: 'localhost:3306', ` as host – Jorge Campos Mar 27 '18 at 12:19

1 Answers1

0

I see that your configuration in sails is OK, so the reason why you cannot connect to the MySQL server is elsewhere. Here are some steps you may want to try:

  1. Use phpMyAdmin to make sure you can connect to your server, but my guess is you will not be able to do that. If you do however, create a user for your DB there and grant all privileges for the DB to that user, and for host try to use "any host". Then adjust your connection according to that user.
  2. In order to check your connection for the new user, the most convenient way is to use the MySQL Workbench tool from here: https://dev.mysql.com/downloads/workbench/
  3. If all of that doesn't help, check this answer: Can't connect to MySQL server on 'localhost' (10061)
logout
  • 621
  • 5
  • 13