Search code examples
mysqlsails.jsmampunix-socket

How to use a unix socket (mamp) instead of a port for sails js db connection?


EDIT (SOLVED):

Ok, thanks to Andrea, the issue has been solved. Strangely enough, both of these syntaxes seem to work:

/* 
  - adapter, not module 
  - host
  - port as socket
*/
connections:{
  local_mysql:{
    adapter: 'sails-mysql', 
    host: 'localhost',
    user: 'root',
    password: 'root',
    port: '/Applications/MAMP/tmp/mysql/mysql.sock', /* socket path as a port */
    database: 'sailstest1'
  }
}

--

/* 
  - module instead of adapter, but you can use both names
  - socketPath instead of port
  - no need for host
*/
connections:{
  local_mysql:{
    module: 'sails-mysql',
    user: 'root',
    password: 'root',
    database: 'sailstest1',
    socketPath: '/Applications/MAMP/tmp/mysql/mysql.sock'
  }
}

Both in my case are written in config/local.js


I'm playing with Sailsjs. For now, I'd like to use the MAMP mysql server instead of installing a new one. I'd like to just connect to the db via socket connection, just like I do through SequelPro. The default MAMP socket is this:

/Applications/MAMP/tmp/mysql/mysql.sock

But where should I tell sails to use it? Standard docs only show the standard connection way:

  someMysqlServer: {
    adapter: 'sails-mysql',
    host: 'YOUR_MYSQL_SERVER_HOSTNAME_OR_IP_ADDRESS',
    user: 'YOUR_MYSQL_USER',
    password: 'YOUR_MYSQL_PASSWORD',
    database: 'YOUR_MYSQL_DB'
  },

Maybe I shoud write it somewhere else?


Solution

  • Try with the options 'socketPath'

      someMysqlServer: {
            module: 'sails-mysql',
            user: 'YOUR_MYSQL_USER',
            password: 'YOUR_MYSQL_PASSWORD',
            database: 'YOUR_MYSQL_DB',
            socketPath: 'YOUR_SOCKET_PATH'
        }
    

    I've found some reference in this issue: https://github.com/balderdashy/sails-mysql/issues/31

    maybe the use of module instead of adapter changes something.

    have a nice day!