I'm getting error : error:Error: Handshake inactivity timeout
Asked
Active
Viewed 1.2k times
0
-
Can you post the NodeJS code in context? – Apr 28 '16 at 06:20
-
see this post: http://stackoverflow.com/questions/20210522/nodejs-mysql-error-connection-lost-the-server-closed-the-connection – Subburaj Apr 28 '16 at 06:23
-
change `host : "127.0.0.1"` to `host : "localhost"` – Abhik Chakraborty Apr 28 '16 at 06:25
-
@Subburaj I had tried that..but I want to connect without setTimeout i.e.I dont want to wake it up by setting timeout – Gayathri Apr 28 '16 at 06:30
-
@Abhik Chakraborty ..It dosn't works..Im receiving the same error. – Gayathri Apr 28 '16 at 06:31
-
@Gayathri post your code in question part not as a comment ... which helps all to find solution – rev_dihazum Apr 28 '16 at 06:32
-
@Gayathri, as what rev_dihazum said, please edit your question and put your code there instead of here. – Apr 28 '16 at 06:35
-
@LFlare sorry Im new to Stackoverflow – Gayathri Apr 28 '16 at 06:58
-
@Subburaj yes..still I'm struggling with this :( – Gayathri Apr 28 '16 at 13:00
-
@Gayathri can you post all the versions?like node,mysql,etc. – Subburaj Apr 28 '16 at 13:12
-
@Subburaj finnaly I found my error...error is in my XAMPP installation – Gayathri Apr 29 '16 at 06:05
-
Good that your problem solved.. – Subburaj Apr 29 '16 at 06:15
3 Answers
1
I connected mysql to node by like this.
Install mysql
npm install mysql
var mysql = require('mysql');
let connection = mysql.createConnection({
host: 'localhost',
user: 'root',
port: '8888', /* port on which phpmyadmin run */
password: 'root',
database: 'dbname',
socketPath: '/Applications/MAMP/tmp/mysql/mysql.sock' //for mac and linux
});
connection.connect(function(err) {
if (err) {
return console.error('error: ' + err.message);
}
console.log('Connected to the MySQL server.');
});

Manish
- 13,047
- 1
- 12
- 9
0
You can use node-mysql, It very easy to use. I have used once, Here is the example :-
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'me',
password : 'secret',
database : 'my_db'
});
connection.connect();
connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
if (err) throw err;
console.log('The solution is: ', rows[0].solution);
});
connection.end();

Bik
- 553
- 10
- 31
0
Use Connection Pool:
var mysql = require('mysql');
var pool = mysql.createPool({
host : 'example.org',
user : 'bob',
password : 'secret'
});
pool.getConnection(function(err, connection) {
// Use the connection
connection.query( 'SELECT something FROM sometable', function(err, rows) {
// And done with the connection.
connection.release();
// Don't use the connection here, it has been returned to the pool.
});
});

Subburaj
- 5,114
- 10
- 44
- 87
-
But I dont know why Im getting this Error: Handshake inactivity timeout – Gayathri Apr 28 '16 at 11:01
-
This is related to node.js. refer this post http://stackoverflow.com/questions/33101869/solving-node-mysql-initialization-errors – Subburaj Apr 28 '16 at 11:10
-