A hook (`orm`) failed to load! sailsjs - mysql

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

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:
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.
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/
If all of that doesn't help, check this answer: Can't connect to MySQL server on 'localhost' (10061)

Related

Getting 'Client does not support authentication protocol requested by server; consider upgrading MySQL client' and alter user doesn't fix this

I'm using knex and have mysql 8 installed. Trying to make a simple connection but getting
'Client does not support authentication protocol requested by server; consider upgrading MySQL client'
const knex = require('knex');
const db = knex({
client: 'mysql',
connection: {
host: '127.0.0.1',
user: 'root',
password: '12345678',
database: 'myDatabase'
},
});
I changed the user to use mysql_native_password by running the query
alter user 'root'#'localhost' identified with mysql_native_password by '12345678';
but still getting the same error when trying to connect.
Everything I found online was telling me that this query will fix the problem, I'm wondering if I might be missing something or if there might be another reason I'm getting this error.
Any help or advice would be much appreciated!
Replace localhost with %, it worked for me.

Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message: Unknown database 'xxx'

I am using code first approach in my project. But when i am trying to run db-migrations by using 'update-database' command i am getting null reference exception and when I am running the application I am getting the following configuration error:
Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message: Unknown database 'xxx'.
Here is the connection string:
<add name="DefaultConnectionString" connectionString="server=localhost;port=3306;Database=cps;uid=root;pwd=root;" providerName="MySql.Data.MySqlClient" />
P.S: It's running fine on the other system.
Your connection string is demanding a MySQL database called cps. It seems likely you have not yet created that database on your local MySQL server.
Pro tip: Always read error message text carefully, asking yourself "what could this mean?"
The solution I got for below error.
Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message: Access denied for user 'root'#'localhost' (using password: YES)
<add name="constring" connectionString="Server=localhost;Uid=root;Database=databasename;Port=3306;" providerName="MySql.Data.MySqlClient"/>
=> Just remove the password
=> If you have 2 local servers with a different port number, just add it or else by default it will take 3306
Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message: Access denied for user 'root'#'localhost' (using password: YES)
from
public string strconn = "SERVER = localhost ;DATABASE=restaurant;UID = root;pwd=12345678;convert zero datetime=True";
become
public string strconn = "SERVER =127.0.0.1 ;DATABASE=restaurant;UID = root;pwd=12345678;convert zero datetime=True";
fix localhost to 127.0.0.1 in connectionstring
Thanks for all the answers, But in my case as #GirishBabuC said its port and need to append the port in connection string in case you are using other then default port.
<add name="constring" connectionString="Server=localhost;Uid=root;Database=databasename;Port=3307;" providerName="MySql.Data.MySqlClient"/>
in my case its 3307.
while installing its asks for port.
This issue could come up depending on which version of MySQL is being targeted. You are welcome to try this solution to see if it works for you. Instead of using the Uid=*;Pwd=*; format, make use of the user=*;password=*; format.
Original Connection String:
Server=localhost;Port=3306;Database=databasename;Uid=sqltracking;Pwd=sqltracking;
One that works
server=localhost;port=3306;database=databasename;user=sqltracking;password=sqltracking;
The first method works on MySql 8, but not on MySql 5.
I haven't dug into the documentation behind these connection string configurations, however, I have noticed a difference between MySQL 5.7 and 8.0 in certain conditions. Although admittedly haven't spent a lot of time to figure out why it happens sometimes.
Also, remember to do a FLUSH PRIVILEGES on your MySQL instance after making any permission changes. This could have an effect as well.

node/mysql/nginx - 502 bad gateway

I'm running a node app on ubuntu server 14.04 with nginx. I have a mysql database, which was initially running on a different server. Everything worked fine, but in an effort to tune performance I moved it onto the same server and I'm getting an error trying to connect through localhost. I'm using node-mysql with the following configuration:
host: 'localhost',
user: 'root',
password: 'xxx',
database: 'xxx'
I haven't really changed anything with mysql after the initial installation, simply created a dump file and ran it to create the database.
I get the following error whenever my app hits the database:
502 (Bad Gateway)
I've searched around but everything I find on this is PHP related.
Update:
Checked the pm2 logs (using pm2 to run node) and it's giving the following error:
ECONNREFUSED 127.0.0.1:3306
Is there something I need to do to open this up?
After being helped in the right direction via the comments and finding the real error, I was able to find the solution here. Needed to supply the mysql socket path in the node-mysql configuration.
host: 'localhost',
user: 'root',
password: 'xxx',
database: 'xxx',
socketPath: '/var/run/mysqld/mysqld.sock'

How to connect to MySQL on 3307 port in ruby dbi

In Ruby
db = DBI.connect("DBI:Mysql:database=db1:host=dbhostname:port=3307", "username", "password")
isn't working for me
using the same details in a direct mysql connection in the command line does...?
What am I missing to get the connection on port 3307 ???
I get the error:
Access denied for user 'username'#'localhost' (using password: YES) (DBI::DatabaseError)
changed order
DBI:Mysql:host=hostname;database=dbname;port=3307 worked for reason I don't really know.

Installation of Agiletoolkit where do I set mysql password for database test?

I am trying out agiletoolkit. I get an error when I try to do the Database test.
PDO error: SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES)
DSN: mysql:host=localhost;dbname=example;charset=utf8
and then there is a traceback that does not really copy so well (It's at the end of this post)
BACKGROUND
I have WAMP installed on my windows 7 machine. I have set a root password for mysql and I have also set that in phpmyadmin3.5.1\config.inc.php so Phpmyadmin works and I can create tables and so on in phpmyadmin.
I have copied the agiletoolkit into my www directory. It shows up as a hyperlink on the front page that WAMP creates. All good. When I click on that I get the agile toolkit I get the "Hello World from your own copy of Agile Toolkit" message -> all good so far.
At the top right of the page are some buttons - Welcome, Examples ... database test....
When I click on "database test", I get the error message shown above.
I assume that somewhere I need to tell agiletoolkit my mysql root password.
But where do I do that or do I do something else.
Thanks in advance
This is the error in full
http://localhost/agiletoolkit/?page=dbtest
BaseException
Database Connection Failed
Additional information:
PDO error: SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES)
DSN: mysql:host=localhost;dbname=example;charset=utf8
C:\wamp\www\agiletoolkit\atk4\lib\BaseException.php:38
Stack trace:
C:\wamp\www\agiletoolkit\atk4\lib/BaseException.php :38 BaseException BaseException->collectBasicData(Null, 1, 0)
C:\wamp\www\agiletoolkit\atk4\lib/AbstractObject.php :292 BaseException BaseException->__construct("Database Connection Failed")
C:\wamp\www\agiletoolkit\atk4\lib/DB.php :67 sample_project_db DB->exception("Database Connection Failed")
C:\wamp\www\agiletoolkit\atk4\lib/ApiCLI.php :329 sample_project_db DB->connect(Null)
C:\wamp\www\agiletoolkit\page/dbtest.php :7 sample_project Frontend->dbConnect()
C:\wamp\www\agiletoolkit\atk4\lib/AbstractObject.php :189 sample_project_dbtest page_dbtest->init()
C:\wamp\www\agiletoolkit\atk4\lib/ApiFrontend.php :92 sample_project Frontend->add("page_dbtest", "dbtest", "Content")
C:\wamp\www\agiletoolkit\atk4\lib/ApiWeb.php :332 sample_project Frontend->layout_Content()
C:\wamp\www\agiletoolkit\atk4\lib/ApiFrontend.php :33 sample_project Frontend->addLayout("Content")
C:\wamp\www\agiletoolkit\atk4\lib/ApiWeb.php :208 sample_project Frontend->initLayout()
C:\wamp\www\agiletoolkit/index.php :15 sample_project Frontend->main()
In your "C:\wamp\www\agiletoolkit" you will see a file called config-distrib.php. Copy paste it and rename it to config.php then change the dsn for connection.
DSN means Data Source Name.
You will find the following line in the config.php file.
$config['dsn']='mysql://root:root#localhost/project';
You can modify it to
$config['dsn']='mysql://root:#localhost/YOURDATABASENAME';
By default the database user is 'root' and password is '' and you are accessing the database on local host.
Also check, this for more information.