Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem connecting to MySQL via unix socket #6880

Open
ZacxDev opened this issue Oct 23, 2019 · 5 comments
Open

Problem connecting to MySQL via unix socket #6880

ZacxDev opened this issue Oct 23, 2019 · 5 comments
Labels
helpful info or workaround mysql Issue only occurs when using MySQL orm Related to models, datastores, orm config, Waterline, sails-hook-orm, etc.

Comments

@ZacxDev
Copy link

ZacxDev commented Oct 23, 2019

Node version: v10.15.3
Sails version (sails): 1.2.3
ORM hook version (sails-hook-orm): 2.1.1
Sockets hook version (sails-hook-sockets): 2.0.0
Organics hook version (sails-hook-organics): 0.16.0
Grunt hook version (sails-hook-grunt): 4.0.1
Uploads hook version (sails-hook-uploads): n/a
DB adapter & version (e.g. sails-mysql@5.55.5): sails-mysql@1.0.1
Skipper adapter & version (e.g. skipper-s3@5.55.5): n/a


Hey team,

I'm trying to connected to my production database using a unix socket path, I am trying to do this because it is the most secure way that GCP allows me to connect.

I looked into #6547, but couldn't get it to work, that issue was a few years old and it looks like they were messing with adapters.js, which does not exist in my installation of sails.

I've tried putting the datastore config both directly in config/env.production.js, as well as in config/datastores.js, with no luck.

Here is my configuration:

      adapter: 'sails-mysql',
      user: 'root',
      password: process.env.MYSQL_ROOT_PASSWORD,
      database: process.env.MYSQL_DATABASE,
      socketPath: process.env.DB_SOCKET_CONNECTION_STRING,

The errors I get vary depending on what I change, but it's usually either ERRCONNECT-REFUSED when it ignores my configuration and tries to use the default development one. Or it's a sails error saying my datastore is invalid because I'm not passing a connectionString:

error: Failed to lift app: Error: There was an error creating a new manager for the connection with a url of: undefined
2019-10-22 21:32:36.677 CDT
2019-10-22 21:32:36.677 CDTUsageError: Could not run createManager() because of a problem:
2019-10-22 21:32:36.677 CDT------------------------------------------------------
2019-10-22 21:32:36.677 CDT• "connectionString" is required, but it was not defined.
2019-10-22 21:32:36.677 CDT------------------------------------------------------

Thanks for any help :)

@sailsbot
Copy link

@ZacxDev Thanks for posting! We'll take a look as soon as possible.

In the mean time, there are a few ways you can help speed things along:

  • look for a workaround. (Even if it's just temporary, sharing your solution can save someone else a lot of time and effort.)
  • tell us why this issue is important to you and your team. What are you trying to accomplish? (Submissions with a little bit of human context tend to be easier to understand and faster to resolve.)
  • make sure you've provided clear instructions on how to reproduce the bug from a clean install.
  • double-check that you've provided all of the requested version and dependency information. (Some of this info might seem irrelevant at first, like which database adapter you're using, but we ask that you include it anyway. Oftentimes an issue is caused by a confluence of unexpected factors, and it can save everybody a ton of time to know all the details up front.)
  • read the code of conduct.
  • if appropriate, ask your business to sponsor your issue. (Open source is our passion, and our core maintainers volunteer many of their nights and weekends working on Sails. But you only get so many nights and weekends in life, and stuff gets done a lot faster when you can work on it during normal daylight hours.)
  • let us know if you are using a 3rd party plugin; whether that's a database adapter, a non-standard view engine, or any other dependency maintained by someone other than our core team. (Besides the name of the 3rd party package, it helps to include the exact version you're using. If you're unsure, check out this list of all the core packages we maintain.)

Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly.

For help with questions about Sails, click here.

@johnabrams7 johnabrams7 added mysql Issue only occurs when using MySQL orm Related to models, datastores, orm config, Waterline, sails-hook-orm, etc. labels Oct 24, 2019
@Jopchumba
Copy link

Hello, sails ships with a default disk, while you feel your project is ready to connect to a database you have to define your connection variables by instaling the sails-MySQL plugin the feed in your variables adapter: 'sails-MySQL',
user: 'root',
password: process.env.MYSQL_ROOT_PASSWORD,
database: process.env.MYSQL_DATABASE,
socket path: process.env.DB_SOCKET_CONNECTION_STRING,
please check the documentation or check for videos tutorials
thanls

@alxndrsn
Copy link

alxndrsn commented Nov 7, 2019

Possibly related: #6888

@johnabrams7
Copy link
Contributor

johnabrams7 commented Nov 18, 2019

@ZacxDev Thanks for exploring this issue. I'll bring this up with the team to get it fixed. Our latest developments for MySQL are in our sails-sql adapter. Since this does appear to be related to #6888 - have you tried @alxndrsn 's workaround (thanks again btw) in the meantime?

@chrismerkle
Copy link

I figure this post is relevant here too for MySQL friends (I was using Postgres but had same issue).

--

I finally got Sails.js to work today with GCP SQL. If you follow the tutorials from Google you have either Unix Sockets or TCP options to try -- and sadly neither work with out of the box sails-postgres.

My workaround was to connect via a VPC connector with a dedicated IP address. This way I can connect to Cloud SQL using a regular Postgres connection string, directly to the DB.

https://cloud.google.com/appengine/docs/legacy/standard/python/outbound-ip-addresses

Then I whitelisted the new dedicated IP in Cloud SQL security settings, and forced SSL to require valid SSL certificates.

It may not be best practice for now, but it works -- and that's one less ticket in the "To Do" queue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
helpful info or workaround mysql Issue only occurs when using MySQL orm Related to models, datastores, orm config, Waterline, sails-hook-orm, etc.
Development

No branches or pull requests

7 participants