MySQL installation is all messed up, trying to untangle it

27 views Asked by At

In the past I've used my local installation of mysql for my relational database needs. But it's been a few months since I used it, I've been working on MongoDB projects for the last year or so. I just started a project, though, where the data is more relational, and I set about to utilize mysql and Sequelize...but I keep getting "ECONNREFUSED" errors.

I fear I've got things all messed up in my attempts to fix this, but I'll post what I can here to see if anything is obvious to someone.

I have mysql installed via Homebrew. When I check for its version with brew search mysql I see both version 5.7 and 8.0 present. I am running node.js version 18.19.1, and Sequelize 6.29.3. On top of all of this, I installed Anaconda for a beginning Python class a couple of months ago (more on that below).

I did a full brew uninstall of mysql, a brew doctor and brew cleanup, then reinstalled mysql, with the same results. Running brew services start mysql gives me a success message; however just entering mysql gives me this:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I've attempted to locate my.cnf in my file system (Mac OS Sonoma 14.2.1)...and it is NOT in any of the places I expect to find it. When I search for my.cnf in the Finder, I find several located not in places like /usr/etc/lib/ or something similar, but instead deep in the Anaconda installation. I assume that the homebrew mysql service is using a my.cnf somewhere, isn't it?

I can confirm that I have NO Anaconda environments running.

I tried to create a my.cnf file with just the reference to use /tmp/mysql.sock, placed it in /etc/mysql, with no success. Under all circumstances, even with the mysql service (allegedly) running from homebrew, when I launch the server I get ConnectionRefusedError [SequelizeConnectionRefusedError]: connect ECONNREFUSED 127.0.0.1:3306.

This is an older project that worked fine when I last touched it, but here is the connection.js file:

const Sequelize = require('sequelize');
require('dotenv').config();

let sequelize;

sequelize = new Sequelize(
  process.env.DB_NAME,
  process.env.DB_USER,
  process.env.DB_PASSWORD,
  {
    host: '127.0.0.1',
    dialect: 'mysql',
    port: 3306
  }
);

module.exports = sequelize;

...and here is server.js:

const path = require('path');
const express = require('express');
const session = require('express-session');
const SequelizeStore = require('connect-session-sequelize')(session.Store);

const routes = require('./controllers');
const sequelize = require('./config/connection');
const helpers = require('./utils/helpers');

const app = express();
const PORT = process.env.PORT || 3001;

const sess = {
    secret: process.env.SECRET,
    cookie: {
        maxAge: (1000 * 60 * 30),
        httpOnly: true
    },
    rolling: true,
    resave: false,
    saveUninitialized: true,
    store: new SequelizeStore({
        db: sequelize,
    })
};

app.use(session(sess));

app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));

app.use(routes);

sequelize.sync({ force: false }).then(() => {
  app.listen(PORT, () => console.log('Now listening'));
});

I tried to launch an even earlier project that just used mysql with no ORM involved, I got the same result (though without the SequelizeError layer).

EDIT:

In trying to start the server using mysql.server start, the server is clearly trying to connect using the resources in Anaconda. However the server still fails to start, with several no such file or directory errors in Anaconda locations.

0

There are 0 answers