I am new to sails.js and i am trying to make it work but unable to install it properly.
During installation, first it was giving MSB4132 issue
then i installed visual studio 2010 to resolve that issue but then is starts showing around 2 pages of red text error.
due to this issue sails new project is working fine but when i am trying to connect it to my sql then it is showing issue.
changes i made for connecting to mysql
In SailsTest/config/connection.js
TestServer: {
adapter: 'sails-mysql',
host: 'localhost',
user: 'root',
password: '',
port: 4343,
database: 'sailstest'
},
In SailsTest/config/model.js
connection: 'TestServer',
migrate: 'safe'
In SailsTest/api/controller/userController.js
module.exports = {
get:function(req, res){
User.find()
.exec(function(err, users){
if(err){
console.log(err);
return res.json(err);
}
return res.json(users);
})
}
};
In SailsTest/config/route.js
'/': {
view: 'homepage'
},
'/user/get':'UserController.get'
after all this on
http://localhost:1337/user/get it is showing following error
{
"error": "E_UNKNOWN",
"status": 500,
"summary": "Encountered an unexpected error",
"raw": {}
}
this is the error log coming.
Error (E_UNKNOWN) :: Encountered an unexpected error
: Could not connect to MySQL:
Error: connect ECONNREFUSED 127.0.0.1:4343
at afterwards (C:\Users\Ashish\Desktop\SailsTest\node_modules\sails-mysql\lib\connections\spawn.js:72:13)
at C:\Users\Ashish\Desktop\SailsTest\node_modules\sails-mysql\lib\connections\spawn.js:40:7
at Handshake.onConnect (C:\Users\Ashish\Desktop\SailsTest\node_modules\mysql\lib\Pool.js:54:9)
at Handshake.Sequence.end (C:\Users\Ashish\Desktop\SailsTest\node_modules\mysql\lib\protocol\sequences\Sequence.js:96:24)
at Protocol.handleNetworkError (C:\Users\Ashish\Desktop\SailsTest\node_modules\mysql\lib\protocol\Protocol.js:358:14)
at PoolConnection.Connection._handleNetworkError (C:\Users\Ashish\Desktop\SailsTest\node_modules\mysql\lib\Connection.js:382:18)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at emitErrorNT (net.js:1256:8)
at nextTickCallbackWith2Args (node.js:455:9)
at process._tickDomainCallback (node.js:410:17)
Related
I am new to deploying in general and I am trying to deploy my back-end node project in aws. the mysql database is successfully deployed and works locally, meanwhile when I try to start the project in production it gives me a timeout error.
Error: connect ETIMEDOUT
at Connection._handleTimeoutError (/home/ubuntu/gmd-server/node_modules/mysql2/lib/connection.js:178:17)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7) {
errorno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
fatal: true
}
I tried to extend the connection time in the node project but nothing changed.
My connection string:
const connection = mysql.createConnection({
host: 'XXXX',
user: 'XXXX',
password: 'XXXX',
database: 'XXXX',
});
How can I fix this problem?
Thanks in advance.
I am using MagicMirror project that can be found on the Github. I have added the MMM-MysqlQuery module. And i have added the database config to the config file. but still gets ENOTFOUND error.
project : https://github.com/MichMich/MagicMirror.git
I have set up the code in a raspberry pi 2. and the mysql database is in the pi localhost.when I run the project using pi terminal i get the ENOTFOUND error.
config: {
connection: {
host: "http://192.168.8.100",
port: 80,
user: "root",
password: "123456789",
database: "mirror"
}
according to understanding this configurations are passed as parameters to the
MMM-MysqlQuery modules' config.js file. which has the db connection initialization.
var mysql = require("mysql");
var con = mysql.createConnection({
host: process.argv[2],
port: process.argv[3],
user: process.argv[4],
password: process.argv[5],
database: process.argv[6]
});
con.connect(function(err) {
if (err) throw err;
con.query(process.argv[7], function(err, result) {
if (err) throw err;
console.log(result);
});
});
And the error i get is like this
Whoops! There was an uncaught exception...
{ Error: getaddrinfo ENOTFOUND http://192.168.8.100
http://192.168.8.100:80
at errnoException (dns.js:50:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
--------------------
at Protocol._enqueue (/home/pi/MagicMirror/modules/MMM-MysqlQuery/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/home/pi/MagicMirror/modules/MMM-MysqlQuery/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at Connection.connect (/home/pi/MagicMirror/modules/MMM-MysqlQuery/node_modules/mysql/lib/Connection.js:118:18)
at Class.socketNotificationReceived (/home/pi/MagicMirror/modules/MMM-MysqlQuery/node_helper.js:25:17)
at Socket.<anonymous> (/home/pi/MagicMirror/modules/node_modules/node_helper/index.js:113:11)
at emitTwo (events.js:126:13)
at Socket.emit (events.js:214:7)
at /home/pi/MagicMirror/node_modules/socket.io/lib/socket.js:513:12
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'http://192.168.8.100',
host: 'http://192.168.8.100',
port: 80,
fatal: true }
please let me know if the code is not enough. and thank you guys for any help I can get.
http://192.168.8.100 isn't a valid hostname, because it isn't a hostname at all -- it's a URL, and includes the scheme http://, which also isn't appropriate for a database connection.
Use simply host: "192.168.8.100".
The next error you will encounter is a side effect of port: 80 also being incorrect. Port 80 is the standard port for an HTTP (web) server... but you are connecting to a database, not a web server. For MySQL, the correct value would be port: 3306 unless your MySQL installation uses a custom port (which it shouldn't).
I created a rest api with Express. on my server.js the i have my mysql connection.. though the connection is made at first. It's working on my local machine properly but when i deployed on AWS EC2 service then i am facing this problem..
server.js
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'localhost',
user: 'myusername',
password: 'mypassword',
database: 'mydatabasename'
});
connection.connect(function (err) {
if (err) throw err;
console.log('connected!');
});
module.exports = connection;
i tried pm 2 handledisconnect() following other project function none worked.getting following error...
restapi#0.0.0 start /home/bcs_quiz_console/bcs-preparation-backend/restapi
npm start
connected!
events.js:180
throw er; // Unhandled 'error' event
^
Error: Connection lost: The server closed the connection.
at Protocol.end (/home/bcs_quiz_console/bcs-preparation-backend/restapi/node_modules/mysql/lib/protocol/Protocol.js:112:13)
at Socket. (/home/bcs_quiz_console/bcs-preparation-backend/restapi/node_modules/mysql/lib/Connection.js:97:28)
at Socket. (/home/bcs_quiz_console/bcs-preparation-backend/restapi/node_modules/mysql/lib/Connection.js:525:10)
at Socket.emit (events.js:208:15)
at endReadableNT (_stream_readable.js:1168:12)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
Emitted 'error' event at:
at Connection._handleProtocolError (/home/bcs_quiz_console/bcs-preparation-backend/restapi/node_modules/mysql/lib/Connection.js:426:8)
at Protocol.emit (events.js:203:13)
at Protocol._delegateError (/home/bcs_quiz_console/bcs-preparation-backend/restapi/node_modules/mysql/lib/protocol/Protocol.js:398:10)
at Protocol.end (/home/bcs_quiz_console/bcs-preparation-backend/restapi/node_modules/mysql/lib/protocol/Protocol.js:116:8)
at Socket. (/home/bcs_quiz_console/bcs-preparation-backend/restapi/node_modules/mysql/lib/Connection.js:97:28)
[... lines matching original stack trace ...]
at processTicksAndRejections (internal/process/task_queues.js:77:11) {
fatal: true,
code: 'PROTOCOL_CONNECTION_LOST'
}
Thank anyone who can help in advance..
I am trying to connect to MySQL server using the mysql_clear_password plugin. I set up the connection configuration for node-mysql2 as follows:
const connectionConfig = {
host: rwConfig.host,
user: rwConfig.user,
database: rwConfig.database,
ssl: {
ca: sslContent
},
password
}
Then to support the mysql_clear_password plugin I added the following (link of the reference i used: https://github.com/sidorares/node-mysql2/issues/438#issuecomment-255343793):
connectionConfig.authSwitchHandler = (data, cb) => {
console.log('In auth switch handler');
if (data.pluginName === 'mysql_clear_password') {
console.log(data);
console.log(data.pluginData.toString('utf8'));
console.log('In mysql clear password');
var tmppassword = connectionConfig.password + '\0';
var buffer = Buffer.from(tmppassword, 'base64');
cb(null, buffer);
}
};
This works when I attempt to connect to my database.
Now I try to do something similar using knexjs. I use the following configuration object:
const knexConfig = {
client: 'mysql2',
connection: connectionConfig,
pool: {
min: 0,
max: 20
},
acquireConnectionTimeout: 10000
};
The connectionConfig I passed in as the value for connection is the same object I used for connecting with node-mysql2. Then I create a knex connection:
const rwConnection = knex(knexConfig);
This for some reason throws this error:
{ Error: Client does not support authentication protocol requested by server; consider upgrading MySQL client
at Packet.asError (node_modules/mysql2/lib/packets/packet.js:703:13)
at ClientHandshake.Command.execute (node_modules/mysql2/lib/commands/command.js:28:22)
at Connection.handlePacket (node_modules/mysql2/lib/connection.js:515:28)
at PacketParser.onPacket (node_modules/mysql2/lib/connection.js:94:16)
at PacketParser.executeStart (node_modules/mysql2/lib/packet_parser.js:77:14)
at TLSSocket.<anonymous> (node_modules/mysql2/lib/connection.js:386:31)
at emitOne (events.js:96:13)
at TLSSocket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at TLSSocket.Readable.push (_stream_readable.js:134:10)
at TLSWrap.onread (net.js:547:20)
code: 'ER_NOT_SUPPORTED_AUTH_MODE',
errno: 1251,
sqlState: '#08004' }
I don't know why this is giving me the error. In the knex documentation (http://knexjs.org/) it says:
The connection options are passed directly to the appropriate database client to create the connection, and may be either an object, or a connection string
Based on that I thought it would just pass the configuration through and make the connection using node-mysql2. Any help would be appreciated.
I figured out the issue and it works now. Knex was not passing on all the attributes to the msyql2 client.
Here is what I did for anyone else who might run into this problem. I modified the configurations that knex was passing to mysql2 in the node_modules/knex/lib/dialect/mysql2 and added authSwitchHandler to the configOptions array.
I would like to connect to MySQL database through Node.js in my Angular Universal project.
Connection code is simple:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'dbname',
port: '8889'
});
connection.connect(function(err) {
if (err) {
console.log("Error connecting to DB: " + err);
throw err;
}
});
First I am getting the following error:
TypeError: Cannot read property 'on' of undefined
at Protocol._enqueue (/Applications/MAMP/htdocs/Angular2/myproject/node_modules/mysql/lib/protocol/Protocol.js:152:5)
...
Then after several seconds there is the following error:
Error connecting to DB: Error: Connection lost: The server closed the connection.
Advice me please what should be done in this case to fix the issue.
Thanks a lot.
If I change the version for zone.js in package.json to 0.7.4, everything works without problems.