PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 16, 2022

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

 March 16, 2022     mamp, mysql, sails.js, unix-socket     No comments   

Issue

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!



Answered By - andrea
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing