javascript - Node.js with mySQL -> Connection refused to 127.0.0.1 : 3306 - Stack Overflow

First, I have this code here for the server, which works perfectlyvar app = require('express'

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
Add a ment  | 

1 Answer 1

Reset to default 4

You 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745524931a4631425.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信