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.