admin管理员组文章数量:1026989
First, I have this code here for the server, which works perfectly
var app = require('express')();
var mysql = require('mysql');
app.get('/', function (req, res) {
res.sendFile(__dirname + "/start.html");
});
app.listen(3000);
But, if I try to create a connection to a database, it says that the connection is refused to 127.0.0.1 : 3036
var db = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'user_data'
});
db.connect();
I am using XAMMP :
Click here -> MySQL / Apache
So what is the problem? I don't understand. I also get this error when I try to access phpMyAdmin : Link to the error
First, I have this code here for the server, which works perfectly
var app = require('express')();
var mysql = require('mysql');
app.get('/', function (req, res) {
res.sendFile(__dirname + "/start.html");
});
app.listen(3000);
But, if I try to create a connection to a database, it says that the connection is refused to 127.0.0.1 : 3036
var db = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'user_data'
});
db.connect();
I am using XAMMP :
Click here -> MySQL / Apache
So what is the problem? I don't understand. I also get this error when I try to access phpMyAdmin : Link to the error
Share Improve this question edited Mar 23, 2017 at 7:26 Caitiff asked Mar 23, 2017 at 7:09 CaitiffCaitiff 573 silver badges11 bronze badges 5- Check if your database is running on port 3306 – LVK Commented Mar 23, 2017 at 7:12
- I am just curious why it doesn't work. I have everything set up, the database is supposed to run on that port and if it doesn't then, well idk – Caitiff Commented Mar 23, 2017 at 7:28
- Okay, I found the 75% of the answer myself. I have the database on specific port 3036, and in the code, it is trying to connect to the default port so that is an error on my part. Still, phpmyadmin refuses to work. Why? – Caitiff Commented Mar 23, 2017 at 7:35
- Because phpMyAdmin also expects the database to be running on port 3306, you need to edit this too – baao Commented Mar 23, 2017 at 7:36
- Wow, yeah correct. Okay thank you! – Caitiff Commented Mar 23, 2017 at 7:38
1 Answer
Reset to default 4You need to specify a port as your database is listening on a non standard port
var db = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'user_data',
port: 3036
});
db.connect();
For phpMyAdmin, you need to find config.inc.php in phpMyAdmin's top level directory and edit the line where it says
$cfg['Servers'][$i]['port']
to the port you are using. And you need to change
$cfg['Servers'][$i]['host']
to 127.0.0.1
instead of localhost, because:
If you use localhost as the hostname, MySQL ignores this port number and connects with the socket, so if you want to connect to a port different from the default port, use 127.0.0.1 or the real hostname in $cfg['Servers'][$i]['host'].
Documentation on phpMyAdmin
First, I have this code here for the server, which works perfectly
var app = require('express')();
var mysql = require('mysql');
app.get('/', function (req, res) {
res.sendFile(__dirname + "/start.html");
});
app.listen(3000);
But, if I try to create a connection to a database, it says that the connection is refused to 127.0.0.1 : 3036
var db = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'user_data'
});
db.connect();
I am using XAMMP :
Click here -> MySQL / Apache
So what is the problem? I don't understand. I also get this error when I try to access phpMyAdmin : Link to the error
First, I have this code here for the server, which works perfectly
var app = require('express')();
var mysql = require('mysql');
app.get('/', function (req, res) {
res.sendFile(__dirname + "/start.html");
});
app.listen(3000);
But, if I try to create a connection to a database, it says that the connection is refused to 127.0.0.1 : 3036
var db = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'user_data'
});
db.connect();
I am using XAMMP :
Click here -> MySQL / Apache
So what is the problem? I don't understand. I also get this error when I try to access phpMyAdmin : Link to the error
Share Improve this question edited Mar 23, 2017 at 7:26 Caitiff asked Mar 23, 2017 at 7:09 CaitiffCaitiff 573 silver badges11 bronze badges 5- Check if your database is running on port 3306 – LVK Commented Mar 23, 2017 at 7:12
- I am just curious why it doesn't work. I have everything set up, the database is supposed to run on that port and if it doesn't then, well idk – Caitiff Commented Mar 23, 2017 at 7:28
- Okay, I found the 75% of the answer myself. I have the database on specific port 3036, and in the code, it is trying to connect to the default port so that is an error on my part. Still, phpmyadmin refuses to work. Why? – Caitiff Commented Mar 23, 2017 at 7:35
- Because phpMyAdmin also expects the database to be running on port 3306, you need to edit this too – baao Commented Mar 23, 2017 at 7:36
- Wow, yeah correct. Okay thank you! – Caitiff Commented Mar 23, 2017 at 7:38
1 Answer
Reset to default 4You need to specify a port as your database is listening on a non standard port
var db = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'user_data',
port: 3036
});
db.connect();
For phpMyAdmin, you need to find config.inc.php in phpMyAdmin's top level directory and edit the line where it says
$cfg['Servers'][$i]['port']
to the port you are using. And you need to change
$cfg['Servers'][$i]['host']
to 127.0.0.1
instead of localhost, because:
If you use localhost as the hostname, MySQL ignores this port number and connects with the socket, so if you want to connect to a port different from the default port, use 127.0.0.1 or the real hostname in $cfg['Servers'][$i]['host'].
Documentation on phpMyAdmin
本文标签: javascriptNodejs with mySQL gt Connection refused to 1270013306Stack Overflow
版权声明:本文标题:javascript - Node.js with mySQL -> Connection refused to 127.0.0.1 : 3306 - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745524929a2154480.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论