0

I installed XAMPP on my machine running OS X (standard installation). I launched XAMPP and clicked the "Start" button in the general tab. The status light turns green.

I try to connect to the service like this:

const express = require('express')
const mysql = require('mysql')

// Create Connection
const db = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '1234',
    //database: 'node-mysql'
}) 

// Connect
db.connect((err) => {
    if(err){
        throw err
    }
    console.log('MySql Connected...')
})

const app = express()

// Create DB
app.get('/creatdb', (req, res) => {
    let sql = 'CREATE DATABASE node-mysql'
    db.query(sql, (err, result) => {
        if (err) throw err
        console.log(result)
        res.send('Database created')
    })
})

app.listen(3000, () => console.log('running on 3000'))

And I see this error:

<path>/app.js:15
        throw err
        ^

Error: connect ECONNREFUSED 127.0.0.1:3306
    at Object._errnoException (util.js:1024:11)
    at _exceptionWithHostPort (util.js:1046:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
    --------------------
    at Protocol._enqueue (/Users/casey/Dev/mysql/node_modules/mysql/lib/protocol/Protocol.js:145:48)
    at Protocol.handshake (/Users/casey/Dev/mysql/node_modules/mysql/lib/protocol/Protocol.js:52:23)
    at Connection.connect (/Users/casey/Dev/mysql/node_modules/mysql/lib/Connection.js:130:18)
    at Object.<anonymous> (/Users/casey/Dev/mysql/app.js:13:4)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)

In the General tab of XAMPP, IP Address shows as 192.168.64.2. Perhaps it needs to be localhost (127.0.0.1). How can I set this? When I go to 192.168.64.2 in my browser I am redirected to an XAMPP dashboard at http://192.168.64.2/dashboard/

Is XAMPP running at the incorrect IP address, if so how can I change it? If the issue is something other than the IP, any idea how I might track the problem down? Thanks.

currenthandle
  • 1,038
  • 2
  • 17
  • 34
  • It's not the XAMPP IP address which is the problem, but rather that there does not appear to be a running MySQL server on the same host as your application server. Have you installed a MySQL "server"? Or did you just install the library and expect it to work? Have you checked that MySQL is running? Do you have a MySQL server but on a different host? These are the reasons for the error message received. – Neil Lunn Nov 02 '17 at 21:17
  • I was under the impression that the MySQL server was installed with XAMPP, I guess that's not the case? – currenthandle Nov 02 '17 at 21:37
  • In the Services tab of XAMPP it shows MySQL, Apache and ProFTPD as all running. I also ran brew install mysql and then stopped and restarted XAMPP and I am seeing the same error. – currenthandle Nov 02 '17 at 21:43
  • If this is a duplicate can you link me to the relevant post please? – currenthandle Nov 02 '17 at 21:49
  • Look Up! Marked duplicates contain the link "on the top of your question". – Neil Lunn Nov 02 '17 at 21:51
  • Well thanks for explaining that. But I already tried that solution, starting MySQL through the XAMPP Control. Also, that is much older version and a totally different platform. – currenthandle Nov 02 '17 at 21:59

0 Answers0