3

I'm using Google Cloud SQL 2nd generation and installed cloud-sql-proxy on my local machine.

On my local machine I'd simply connect to 127.0.0.1:3306 and this has been working fine, in NodeJs, Php and using the mysql command line client.

On Google App Engine Managed VM (flexible environment) i'm using unix_socket or socketPath '/cloudsql/MY_PROJECT_ID:us-central1:SQL_INSTANCE' this has been working fine too, in both, Php and NodeJs.

What doesn't work is MySQL Workbench, I can't figure out how to get it to connect. Does it use another protocol or is cloud-sql-proxy for command line only ?

Here is how I start cloud-sql-proxy

this works:

./cloud_sql_proxy \
  -instances=MY_PROJECT:us-central1:MY_SQL_INSTANCE=tcp:3306 \
  -credential_file='/Users/ME/SomeFolder/MY_SERVICE_ACC_KEY.json'

after that I'd use MySQL Workbench to try to connect to 127.0.0.1:3306, but I always get an error :

SSL connection error: socket layer receive error

local PHP, NodeJS and mysql client work though.

Any help would be appreciated

AlessioX
  • 3,167
  • 6
  • 24
  • 40
Suau
  • 4,628
  • 22
  • 28

2 Answers2

5

Ok, I got it working and believe it might be useful for others too:

I couldn't get it working over the tcp connection, but I figured out how to use the socket method running without fuse:

sudo  ./cloud_sql_proxy \
  -dir=/cloudsql \
  -instances=MY_PROJECT:MY_SQL_REGION:MY_SQL_INSTANCE \
  -credential_file='/Users/ME/some_folder/MY_SERVICE_ACC_KEY.json'

couple of things here:

  1. The folder /cloudsql has to already exists e.g. sudo mkdir /cloudsql
  2. Don't mistype that folder name, really don't
  3. Don't specify the tcp port after instances or it will use a tcp connection instead.
  4. sudo is necessary

In MySQL Workbench:

  1. Select Database > Manage Connections...
  2. Under Connection > Connection Method choose Standard (TCP/IP)
  3. Under Parameters set Host: localhost Port:3306 (although I don't think it matters)
  4. Goto Advanced > Others: enter socket=/cloudsql/MY_PROJECT:MY_SQL_REGION:MY_SQL_INSTANCE
  5. Click Test Connection it should as for your username and password, success.
Suau
  • 4,628
  • 22
  • 28
  • 1
    ... but I'd still be interested to know why it won't work over TCP/IP – Suau Apr 03 '16 at 18:05
  • But it works over TCP/P. Your step 2 in WB indicates that. o_O – Mike Lischke Apr 04 '16 at 06:46
  • @MikeLischke I assume the socket option from step 4 overrides that, as i can put anything into host and it still works. Check the comments under Vadims thread, it's a MySQL Workbench bug. – Suau Apr 04 '16 at 10:34
  • Note: sudo is only needed if the user running the "cloud_sql_proxy" does not have permissions to read/write files in the "/cloudsql" directory. – Kevin Malachowski Apr 04 '16 at 19:11
1

This error indicates that MySQL Workbench is requesting an SSL connection, which is not supported via the proxy. The proxy always uses SSL between the local machine and the instance so there's no need to enable SSL at the MySQL protocol level.

Can you try turning off SSL in MySQL Workbench connection settings?

Vadim
  • 4,996
  • 1
  • 26
  • 30
  • 1
    I did that yesterday in a act of desperation, but I gave it another try and changed from 'If available' to 'Never', still the same error. Any other place where I should disable SSL ? – Suau Apr 04 '16 at 01:32
  • It's possible you are hitting this bug: https://bugs.mysql.com/bug.php?id=74896. What OS are you running this on? – Vadim Apr 04 '16 at 01:34
  • OS X 10.11.4, I looked through the bug report and this might be really it. – Suau Apr 04 '16 at 02:35
  • We're looking into how we can improve the SSL handling in the proxy connectivity to handle this issue. We have some ideas on what we can do to prevent this from happening. For now you may have to stick to unix sockets. – Vadim Apr 04 '16 at 03:02
  • 1
    Confirmed, it's a Workbench (6.3.6 build 511 CE 64bit OS X) bug, it simply won't honour the SSL settings no matter what. it is working fine on 6.2.5.0 build 397 32bit OS X. – Suau Apr 04 '16 at 03:24
  • thanks for the help, i'll add it to the bug report you mentioned earlier. I don't see that as a Cloud-SQL-Proxy issue, as it is working fine with all the other tools. Just one thing, it took me a while to figure out the options with `cloud_sql_proxy`, partly because if used with `dir=...instances...=tcp:3306` it would still print out `Socket Prefix: /cloudsql` which is confusing, because it isn't really using sockets. – Suau Apr 04 '16 at 03:33
  • just one more thing, I also used my local MySQL installation, to which it also connects without SSL and this works. It seems like Workbench will always give it a try, as if stuck in 'If available' mode. But the local MySQL installation seems to report back properly that SSL is not available, maybe that's a thing cloud_sql_proxy could also handle ? – Suau Apr 04 '16 at 04:13
  • Yes, that's one thing we are looking at (modifying the server handshake message to not report SSL support). – Vadim Apr 04 '16 at 04:15