Trying to Connect to database in PHP using PDO and Cloud SQL Proxy

3,141 views
Skip to first unread message

wob...@yblew.com

unread,
Mar 14, 2016, 12:19:24 PM3/14/16
to Google Cloud SQL discuss
I tried to connect  to database in  PHP using PDO and Cloud SQL Proxy but have no luck. I keep getting 



Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory'

Im using

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
$pdo = new PDO('mysql:unix_socket=/cloudsql/<your-project-id>:<your-instance-name>;dbname=db', 
'db', 
'db'
);
$statement = $pdo->query("SHOW TABLES;");
$row = $statement->fetch(PDO::FETCH_ASSOC);
echo htmlentities($row['_message']);
?>

Has anyone had any luck connecting

Vadim Berezniker

unread,
Mar 14, 2016, 12:25:13 PM3/14/16
to Google Cloud SQL discuss
Where are you running your application? On your local machine?

The socket name should be project_id:region:instance_name. 
You should be able to run "ls /cloudsql" and see the sockets there.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/411eb6c1-fafa-4613-812d-b36728f447d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

wob...@yblew.com

unread,
Mar 14, 2016, 12:31:21 PM3/14/16
to Google Cloud SQL discuss
ls /cloudsql give me README.

I changed the socket name to "project_id:region:instance_name. " but no luck 

On Monday, March 14, 2016 at 12:25:13 PM UTC-4, Vadim Berezniker wrote:
Where are you running your application? On your local machine?

The socket name should be project_id:region:instance_name. 
You should be able to run "ls /cloudsql" and see the sockets there.

On Mon, Mar 14, 2016 at 9:19 AM <wob...@yblew.com> wrote:
I tried to connect  to database in  PHP using PDO and Cloud SQL Proxy but have no luck. I keep getting 



Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory'

Im using

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
$pdo = new PDO('mysql:unix_socket=/cloudsql/<your-project-id>:<your-instance-name>;dbname=db', 
'db', 
'db'
);
$statement = $pdo->query("SHOW TABLES;");
$row = $statement->fetch(PDO::FETCH_ASSOC);
echo htmlentities($row['_message']);
?>

Has anyone had any luck connecting

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

Vadim Berezniker

unread,
Mar 14, 2016, 12:40:43 PM3/14/16
to Google Cloud SQL discuss
What is the command you are using to start the proxy?

To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/02317d1f-a4d1-467e-bff3-2132901a0ded%40googlegroups.com.

wob...@yblew.com

unread,
Mar 14, 2016, 12:47:58 PM3/14/16
to Google Cloud SQL discuss
 sudo ./cloud_sql_proxy -dir=/cloudsql -fuse -credential_file=/root/developmentDB.json &
[1] 31266
[root@dev /]# 2016/03/14 12:46:39 couldn't unmount fuse directory "/cloudsql": &errors.errorString{s:"exit status 1: fusermount: failed to unmount /cloudsql: Invalid argument"}
2016/03/14 12:46:39 Mounting "/cloudsql"...
2016/03/14 12:46:39 Mounted "/cloudsql"
2016/03/14 12:46:39 Socket prefix: /cloudsql
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

Vadim Berezniker

unread,
Mar 14, 2016, 4:41:10 PM3/14/16
to google-cloud...@googlegroups.com
Can you double check the instance connection string?
You should use the value that is shown as the "instance connection string" on the instance page in the Developer Console.

instance_name.png

To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/ce76a1fc-2c41-4a64-ae8d-9f9279ecf8e0%40googlegroups.com.

wob...@yblew.com

unread,
Mar 14, 2016, 5:20:44 PM3/14/16
to Google Cloud SQL discuss
I double checked and it's still not working. I can connect to it using mysql on the command line but not via PHP/PDO
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

Kevin Malachowski

unread,
Mar 14, 2016, 6:30:12 PM3/14/16
to Google Cloud SQL discuss
What does the proxy print out after you try to connect using PHP?

Can you try running the proxy with the following commands?

sudo ./cloud_sql_proxy -dir=/cloudsql -instances="<your-project-id>:<the-region>:<your-instance-name>" -credential_file=/root/developmentDB.json

wob...@yblew.com

unread,
Mar 14, 2016, 7:05:37 PM3/14/16
to Google Cloud SQL discuss
Kevin, I think it worked. Will do more testing and update you

2016/03/14 18:56:37 Got a connection for "<your-project-id>:<the-region>:<your-instance-name>"
2016/03/14 18:56:37 from "<your-project-id>:<the-region>:<your-instance-name>" via IP:3307: read tcp IP->IP:3307: use of closed network connection

But two things: 

1. What is really the purpose of CREATE USER name_of_user@'cloudsqlproxy~%';  in your documentation. I'm still a bit confused about it? I should be able to login using regular mysql username and password from php right Or I need to have that?
2.  How do I silent the print out from proxy and how can I keep the command running even after server reboot?

Kevin Malachowski

unread,
Mar 14, 2016, 7:37:04 PM3/14/16
to google-cloud...@googlegroups.com
Just a quick question: are you actually swapping in your project id, the region of your instance, and the instances name? I can't tell if you're copy-pasting and manually redacting your project/region/instance (I agree, you shouldn't be posting this info on this public forum) or if you're literally trying to connect to  "<your-project-id>:<the-region>:<your-instance-name>".

Answers to your questions inline:

On Mon, Mar 14, 2016 at 4:05 PM, <wob...@yblew.com> wrote:
Kevin, I think it worked. Will do more testing and update you

2016/03/14 18:56:37 Got a connection for "<your-project-id>:<the-region>:<your-instance-name>"
2016/03/14 18:56:37 from "<your-project-id>:<the-region>:<your-instance-name>" via IP:3307: read tcp IP->IP:3307: use of closed network connection

But two things: 

1. What is really the purpose of CREATE USER name_of_user@'cloudsqlproxy~%';  in your documentation. I'm still a bit confused about it? I should be able to login using regular mysql username and password from php right Or I need to have that?

If you are using the proxy, you should create a user with a hostname 'cloudsqlproxy~%'; this user will only be available for connections that come in through the proxy. It is not strictly required but it is definitely suggested because it is safe to create this user without a password regardless of the firewall configuration of your instance.

Note that you don't specify the hostname when connecting to a Cloud SQL instance (using the proxy or not using the proxy), it is inferred by the database itself when a new connection comes in.

 
2.  How do I silent the print out from proxy and how can I keep the command running even after server reboot?

The proxy prints out its logs on standard error. You can redirect this output to a file named 'proxy.log' by doing something like this:

./cloud_sql_proxy    YOUR_OTHER_ARGUMENTS_HERE    2>proxy.log   &

(the '&' causes the process to run in the background)

On unix-like systems, you can cause the output to be ignored by redirecting it to the file located at '/dev/null'. I suggest writing the output to a file or somehow hooking into your system's logging infrastructure, though. It will be easier to debug problems you may encounter in the future when you have access to the logs that the proxy writes.

As for keeping the proxy up after a reboot, you can configure your system to run the proxy when the server starts up. Every system is different, so I can't give specific advice unless you give more info about your specific server. For example, can you find other services that run on startup that you can model after? I find that searching the internet for your operating system along with something along the lines of "run program on startup" yields good results.

wob...@yblew.com

unread,
Mar 15, 2016, 2:42:49 AM3/15/16
to Google Cloud SQL discuss
To your question, yes I’m replacing the ips and ports

  1. So to confirm, using fuse with PDO is not advised right? When I set it up with fuse, I see a “README” file in my /cloudsql directory with error (no such file or directory) but when I set it up with “-instances” I see <your-project-id>:<the-region>:<your-instance-name> file in /cloudsql directory with a successful connection
  2. Let’s say I want access to multiple instances how will I achieve that?
  3. When you say “Note that you don't specify the hostname when connecting to a Cloud SQL instance (using the proxy or not using the proxy), it is inferred by the database itself when a new connection comes in.” what do you mean? Just a reminder that I’m running the proxy on a on premise server to connect to my instance in google cloud sql.
  4. How stable is the proxy  sql. Does it hang sometimes? Can I expect to run this on production?
  5. When I create name_of_user@'cloudsqlproxy~% in mysql, I don’t need to assign any privileges to the database I need right?
  6. When I create name_of_user@'cloudsqlproxy~% is that the username with no password I use to connect to my db in my php code?

Just a suggestion. I think the common name of the ssl certificate on the cloud sql instance should be a name with no colon; set of alphanumeric ASCII characters (a-z, A-Z, 0-9). Let me tell you why. When I tried to first access the db with PHP/PDO and ssl certificates, it failed peer validation which makes sense because you guys use CN and IP that does not match. If the CN was without colon maybe I can map the ip and the CN in my hosts file so that when peer validation is done, it can check my hosts file before it touches the DNS and pass. This would have been a quick fix instead of people moving to AWS RDS or waiting for PHP to implement CLIENT_SSL_DONT_VERIFY_SERVER_CERT. (https://bugs.php.net/bug.php?id=71003

Thanks your for help

Kevin Malachowski

unread,
Mar 15, 2016, 3:21:10 AM3/15/16
to google-cloud...@googlegroups.com, Easwar Swaminathan
On Mon, Mar 14, 2016 at 11:42 PM, <wob...@yblew.com> wrote:
To your question, yes I’m replacing the ips and ports

  1. So to confirm, using fuse with PDO is not advised right? When I set it up with fuse, I see a “README” file in my /cloudsql directory with error (no such file or directory) but when I set it up with “-instances” I see <your-project-id>:<the-region>:<your-instance-name> file in /cloudsql directory with a successful connection
I don't know if we can say that, yet. A teammate tried to reproduce your issue using FUSE with PDO (right, Vadim?), so it doesn't appear to be a specific issue with FUSE. The fact that you only see the README is not a bad thing; FUSE allows the proxy to create a file in that directory right when something else tries to access a file in that directory. Any file you try to access should appear to be there (try running `ls /cloudsql/asdfasdfasdfas`, it should show up as a symbolic link (but of course if you try to connect to that socket things won't work, as it isn't a correctly formatted name)). Therefore it is suspect to me that the error you got was 'no such file or directory', as (as far as I can remember) that should never happen unless something is misconfigured somehow.

Note that passing the '-instances' will cause the socket file to exist in the /cloudsql directory but doesn't necessarily mean that the connection works; you could put many things on the commandline and the proxy will open up a socket in that directory. It's just that when you try to connect to that unix socket things won't work.

I would like to help you get FUSE working on your setup, it is a nicer experience than listing instances on the command line. If you are able to get things to work with the '-instances' flag, I suggest replacing the '-instances' flag with '-fuse' and trying again (without changing your PHP app). What does the proxy write out when your PHP server tries to access the /cloudsql directory when '-fuse' is passed to the proxy?
 
  1. Let’s say I want access to multiple instances how will I achieve that?
'-instances' takes a comma-separated list of instances to connect to. And if you get -fuse to work then you will be able to connect to any number of instances just by attempting to connect to files in the /cloudsql directory.
  1. When you say “Note that you don't specify the hostname when connecting to a Cloud SQL instance (using the proxy or not using the proxy), it is inferred by the database itself when a new connection comes in.” what do you mean? Just a reminder that I’m running the proxy on a on premise server to connect to my instance in google cloud sql.
Sorry to confuse you, I was just providing extra info in case you didn't understand what a MySQL user's hostname meant (I don't know how much you know about MySQL, so I wanted to educate if I could!).

You don't have to create a user that has a hostname of `cloudsqlproxy~%`, but it is suggested that you create that user and use the user when using the proxy. It will decrease the chance of accidentally opening up your database to access that you didn't mean to. I can be more specific about an example of accidental misconfiguration if you want. 
  1. How stable is the proxy  sql. Does it hang sometimes? Can I expect to run this on production?
If the proxy hangs, please file an issue on the github with specifics about how and when you encountered the issue. We have a prober that continually uses the proxy and that is very stable, but there's always interesting things that can go on in other people's setups that are hard to predict. As always, feel free to post on this forum or even email me directly with information that you don't want to be public.
  1. When I create name_of_user@'cloudsqlproxy~% in mysql, I don’t need to assign any privileges to the database I need right?
There are no special permissions that you need to give that user when using the proxy.
  1. When I create name_of_user@'cloudsqlproxy~% is that the username with no password I use to connect to my db in my php code?
Yep! Only users with hostname of 'cloudsqlproxy~%' will always be safe without a password (this is why it's good to create such a user when using the proxy). A user with that hostname will not be accessible to entities connecting to the database that don't use the proxy.

Just a suggestion. I think the common name of the ssl certificate on the cloud sql instance should be a name with no colon; set of alphanumeric ASCII characters (a-z, A-Z, 0-9). Let me tell you why. When I tried to first access the db with PHP/PDO and ssl certificates, it failed peer validation which makes sense because you guys use CN and IP that does not match. If the CN was without colon maybe I can map the ip and the CN in my hosts file so that when peer validation is done, it can check my hosts file before it touches the DNS and pass. This would have been a quick fix instead of people moving to AWS RDS or waiting for PHP to implement CLIENT_SSL_DONT_VERIFY_SERVER_CERT. (https://bugs.php.net/bug.php?id=71003

+Easwar to comment on PHP verification of SSL certs, he knows more than I do. The friction of SSL certificate setup is the reason that we developed the Proxy: using it gives you all of the safety of SSL certs without having to go through the trouble of setting up SSL certificates. Ideally you'll be able to use the proxy instead of having to manually set up SSL certs.


Thanks your for help




On Monday, March 14, 2016 at 7:37:04 PM UTC-4, Kevin Malachowski wrote:
Just a quick question: are you actually swapping in your project id, the region of your instance, and the instances name? I can't tell if you're copy-pasting and manually redacting your project/region/instance (I agree, you shouldn't be posting this info on this public forum) or if you're literally trying to connect to  "<your-project-id>:<the-region>:<your-instance-name>".

Answers to your questions inline:

On Mon, Mar 14, 2016 at 4:05 PM, <wob...@yblew.com> wrote:
Kevin, I think it worked. Will do more testing and update you

2016/03/14 18:56:37 Got a connection for "<your-project-id>:<the-region>:<your-instance-name>"
2016/03/14 18:56:37 from "<your-project-id>:<the-region>:<your-instance-name>" via IP:3307: read tcp IP->IP:3307: use of closed network connection

But two things: 

1. What is really the purpose of CREATE USER name_of_user@'cloudsqlproxy~%';  in your documentation. I'm still a bit confused about it? I should be able to login using regular mysql username and password from php right Or I need to have that?

If you are using the proxy, you should create a user with a hostname 'cloudsqlproxy~%'; this user will only be available for connections that come in through the proxy. It is not strictly required but it is definitely suggested because it is safe to create this user without a password regardless of the firewall configuration of your instance.

Note that you don't specify the hostname when connecting to a Cloud SQL instance (using the proxy or not using the proxy), it is inferred by the database itself when a new connection comes in.

 
2.  How do I silent the print out from proxy and how can I keep the command running even after server reboot?

The proxy prints out its logs on standard error. You can redirect this output to a file named 'proxy.log' by doing something like this:

./cloud_sql_proxy    YOUR_OTHER_ARGUMENTS_HERE    2>proxy.log   &

(the '&' causes the process to run in the background)

On unix-like systems, you can cause the output to be ignored by redirecting it to the file located at '/dev/null'. I suggest writing the output to a file or somehow hooking into your system's logging infrastructure, though. It will be easier to debug problems you may encounter in the future when you have access to the logs that the proxy writes.

As for keeping the proxy up after a reboot, you can configure your system to run the proxy when the server starts up. Every system is different, so I can't give specific advice unless you give more info about your specific server. For example, can you find other services that run on startup that you can model after? I find that searching the internet for your operating system along with something along the lines of "run program on startup" yields good results.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-cloud-sql-discuss/AsVdpcRF5gA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-cloud-sql-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/6330a422-365f-4069-b2ff-f764e2b09371%40googlegroups.com.

wob...@yblew.com

unread,
Mar 15, 2016, 6:21:14 AM3/15/16
to Google Cloud SQL discuss, eas...@google.com

I would like to help you get FUSE working on your setup, it is a nicer experience than listing instances on the command line. If you are able to get things to work with the '-instances' flag, I suggest replacing the '-instances' flag with '-fuse' and trying again (without changing your PHP app). What does the proxy write out when your PHP server tries to access the /cloudsql directory when '-fuse' is passed to the proxy?


I get “no file or directory” error. Is as if php/pdo need to see the file there. Question, I’m using CentOs 7. besides “yum install fuse”, is there any packages I’m missing?




You don't have to create a user that has a hostname of `cloudsqlproxy~%`, but it is suggested that you create that user and use the user when using the proxy. It will decrease the chance of accidentally opening up your database to access that you didn't mean to. I can be more specific about an example of accidental misconfiguration if you want. 



can you give me an example :) I like to learn:)



I will do more tests and update you

To unsubscribe from this group and all its topics, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

wob...@yblew.com

unread,
Mar 15, 2016, 8:17:24 AM3/15/16
to Google Cloud SQL discuss, eas...@google.com
To add to my previous post what is the right way to stop the socket? just kill the pid?

Vadim Berezniker

unread,
Mar 15, 2016, 2:15:34 PM3/15/16
to google-cloud...@googlegroups.com, Easwar Swaminathan
On Tue, Mar 15, 2016 at 12:21 AM 'Kevin Malachowski' via Google Cloud SQL discuss <google-cloud...@googlegroups.com> wrote:
On Mon, Mar 14, 2016 at 11:42 PM, <wob...@yblew.com> wrote:
To your question, yes I’m replacing the ips and ports

  1. So to confirm, using fuse with PDO is not advised right? When I set it up with fuse, I see a “README” file in my /cloudsql directory with error (no such file or directory) but when I set it up with “-instances” I see <your-project-id>:<the-region>:<your-instance-name> file in /cloudsql directory with a successful connection
I don't know if we can say that, yet. A teammate tried to reproduce your issue using FUSE with PDO (right, Vadim?), so it doesn't appear to be a specific issue with FUSE. The fact that you only see the README is not a bad thing; FUSE allows the proxy to create a file in that directory right when something else tries to access a file in that directory. Any file you try to access should appear to be there (try running `ls /cloudsql/asdfasdfasdfas`, it should show up as a symbolic link (but of course if you try to connect to that socket things won't work, as it isn't a correctly formatted name)). Therefore it is suspect to me that the error you got was 'no such file or directory', as (as far as I can remember) that should never happen unless something is misconfigured somehow.

Yes, I tested it and it worked for me on Ubuntu 14.04. 
We can also try testing on a clean CentOS 7 image.
 
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/CAB%3DH8NWDLaKB1dRUChwacJw0hh0vw6C7AnmQvvb1%2Bzq51GF5cg%40mail.gmail.com.

Vadim Berezniker

unread,
Mar 15, 2016, 2:18:29 PM3/15/16
to google-cloud...@googlegroups.com, eas...@google.com
Depends on how you are starting it. If you are starting it manually, killing the PID is probably the best way.

We should probably provide some example systemd/upstart configs for running the proxy as a service.

To unsubscribe from this group and all its topics, send an email to google-cloud-sql-d...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/99cf2b0d-8e18-4535-a479-31bc20979646%40googlegroups.com.

wob...@yblew.com

unread,
Mar 15, 2016, 2:22:42 PM3/15/16
to Google Cloud SQL discuss, eas...@google.com
Vadim, 

1.so you were able to access the socket using fuse in PHP/PDO? Can you share your sample code?

2. Can you try it on centos 7 64 bit please?

3. We should probably provide some example systemd/upstart configs for running the proxy as a service. --> that will be great if you can share it
To unsubscribe from this group and all its topics, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

Vadim Berezniker

unread,
Mar 15, 2016, 2:25:54 PM3/15/16
to Google Cloud SQL discuss, eas...@google.com
I used the sample code you pasted :) 

We'll try it on CentOS 7.

I filed a issue to add sample service configs: https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/4

To unsubscribe from this group and all its topics, send an email to google-cloud-sql-d...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/08f0e3c7-f9f5-439f-a174-ccad77c2f260%40googlegroups.com.

Kevin Malachowski

unread,
Mar 15, 2016, 2:27:27 PM3/15/16
to google-cloud...@googlegroups.com, Easwar Swaminathan
On Tue, Mar 15, 2016 at 5:17 AM, <wob...@yblew.com> wrote:
To add to my previous post what is the right way to stop the socket? just kill the pid?

When the proxy exits normally, all of the sockets in the /cloudsql directory will be deleted. I actually don't know if there's a way for the proxy to undergo a clean shutdown though... there won't be a memory leak or anything lasting on your system, though, just some leftover sockets in that directory. It would be safe for you to 'rm' those if you felt like they were annoying.
 


On Tuesday, March 15, 2016 at 6:21:14 AM UTC-4, wob...@yblew.com wrote:

I would like to help you get FUSE working on your setup, it is a nicer experience than listing instances on the command line. If you are able to get things to work with the '-instances' flag, I suggest replacing the '-instances' flag with '-fuse' and trying again (without changing your PHP app). What does the proxy write out when your PHP server tries to access the /cloudsql directory when '-fuse' is passed to the proxy?


I get “no file or directory” error. Is as if php/pdo need to see the file there. Question, I’m using CentOs 7. besides “yum install fuse”, is there any packages I’m missing?



Maybe CentOS has something funky going on. Vadim said that he just copy-pasted your code and it worked (on an ubuntu system), so I'll try to reproduce what you're seeing on your OS (probably not today, might have time tomorrow).


You don't have to create a user that has a hostname of `cloudsqlproxy~%`, but it is suggested that you create that user and use the user when using the proxy. It will decrease the chance of accidentally opening up your database to access that you didn't mean to. I can be more specific about an example of accidental misconfiguration if you want. 



can you give me an example :) I like to learn:)

Sure :)

Say I set up my database and assume that I only want to use the proxy. I create a user 'server'@'%' (without a password) and, since the proxy doesn't respect authorized networks, I don't authorize any networks to connect to my database. All is good in the world: the database is only accessible via the proxy (and access to the database is secured via Google-account based auth rather than mysql-level passwords).

Three days later a coworker of mine wants to access the database via IP rather than the proxy. They have ownership of the database, so they add an IP address to the authorized networks of the database, create a user with a password, and use it. Things are still OK for now, but things might not always be that way: my server (using the proxy) still is happily using the proxy without a password and my coworker is using their account with a password, but they didn't realize our workstations' IPs are provided via DHCP: each time they restart their computer there's a chance that their old IP will get passed on to another computer and they will get a different IP. At that point someone else within the company might have network level access to the database.

In a normal setup, a strong mysql-level password will prevent this (potentially malicious) actor from accessing the database, but since I initially set up the database to only use the proxy I assumed that I didn't need a password. This can happen at any scale - if my coworker doesn't realize that there exists a user without a password in their database then they might decide to allow network access from the entire company.

Creating a user with a hostname of 'cloudsqlproxy~%' requires that the login occurs from the proxy. No matter which coworkers whitelist which networks, the use of this password-less user will be safe because it is guaranteed that the connection is already secured via Google-account based authentication.

 


I will do more tests and update you

Looking forward to hearing back!
 
To unsubscribe from this group and all its topics, send an email to google-cloud-sql-d...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-cloud-sql-discuss/AsVdpcRF5gA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-cloud-sql-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/99cf2b0d-8e18-4535-a479-31bc20979646%40googlegroups.com.

Vadim Berezniker

unread,
Mar 15, 2016, 3:49:53 PM3/15/16
to google-cloud...@googlegroups.com, eas...@google.com
It works for me on a clean CentOS 7.2 install. 
How are you running your test script? Command line? Under a server? 
Is your PHP server running directly in the VM or is it running in a container?

On Tue, Mar 15, 2016 at 11:22 AM <wob...@yblew.com> wrote:
To unsubscribe from this group and all its topics, send an email to google-cloud-sql-d...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/08f0e3c7-f9f5-439f-a174-ccad77c2f260%40googlegroups.com.

wob...@yblew.com

unread,
Mar 15, 2016, 3:53:43 PM3/15/16
to Google Cloud SQL discuss, eas...@google.com
Thank you both.


Kevin : The example was great! 


Vadim:

hmm that's odd...

I'm testing this under apache/php/pdo, not on google cloud

did you install any packages on your server?

Also When can I expect the service script?

Vadim Berezniker

unread,
Mar 15, 2016, 3:59:27 PM3/15/16
to Google Cloud SQL discuss, eas...@google.com
But you're not running the apache server under a docker container, or anything like that, right?
I installed just the basic packages: php-cli, php-mysql, php-pdo, fuse

Please watch https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/4 for future updates about example service configs.


--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.

wob...@yblew.com

unread,
Mar 15, 2016, 4:03:10 PM3/15/16
to Google Cloud SQL discuss, eas...@google.com
But you're not running the apache server under a docker container, or anything like that, right? --> Correct

When I do php index.php on the command line it WORKS but not when I call it from apache/php, I get : Connection failed: SQLSTATE[HY000] [2002] No such file or directory


On Tuesday, March 15, 2016 at 3:59:27 PM UTC-4, Vadim Berezniker wrote:
But you're not running the apache server under a docker container, or anything like that, right?
I installed just the basic packages: php-cli, php-mysql, php-pdo, fuse

Please watch https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/4 for future updates about example service configs.


On Tue, Mar 15, 2016 at 12:53 PM <wob...@yblew.com> wrote:
Thank you both.


Kevin : The example was great! 


Vadim:

hmm that's odd...

I'm testing this under apache/php/pdo, not on google cloud

did you install any packages on your server?

Also When can I expect the service script?

On Tuesday, March 15, 2016 at 3:49:53 PM UTC-4, Vadim Berezniker wrote:
It works for me on a clean CentOS 7.2 install. 
How are you running your test script? Command line? Under a server? 
Is your PHP server running directly in the VM or is it running in a container?

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

wob...@yblew.com

unread,
Mar 15, 2016, 11:18:05 PM3/15/16
to Google Cloud SQL discuss
Vadim:

Were you able to reproduce the issue?

Vadim Berezniker

unread,
Mar 16, 2016, 12:38:21 AM3/16/16
to Google Cloud SQL discuss
Are you using a "stock" PHP setup for Apache from CentOS or have a more customized configuration?

On Tue, Mar 15, 2016 at 8:18 PM <wob...@yblew.com> wrote:
Vadim:

Were you able to reproduce the issue?

On Tuesday, March 15, 2016 at 4:03:10 PM UTC-4, wob...@yblew.com wrote:
But you're not running the apache server under a docker container, or anything like that, right? --> Correct

When I do php index.php on the command line it WORKS but not when I call it from apache/php, I get : Connection failed: SQLSTATE[HY000] [2002] No such file or directory

On Tuesday, March 15, 2016 at 3:59:27 PM UTC-4, Vadim Berezniker wrote:
But you're not running the apache server under a docker container, or anything like that, right?
I installed just the basic packages: php-cli, php-mysql, php-pdo, fuse

Please watch https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/4 for future updates about example service configs.


On Tue, Mar 15, 2016 at 12:53 PM <wob...@yblew.com> wrote:
Thank you both.


Kevin : The example was great! 


Vadim:

hmm that's odd...

I'm testing this under apache/php/pdo, not on google cloud

did you install any packages on your server?

Also When can I expect the service script?

On Tuesday, March 15, 2016 at 3:49:53 PM UTC-4, Vadim Berezniker wrote:
It works for me on a clean CentOS 7.2 install. 
How are you running your test script? Command line? Under a server? 
Is your PHP server running directly in the VM or is it running in a container?

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/2811c05d-72b6-463c-81b0-a8de76e28989%40googlegroups.com.

wob...@yblew.com

unread,
Mar 16, 2016, 12:39:35 AM3/16/16
to Google Cloud SQL discuss
"stock" PHP setup for Apache from CentOS

To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

Vadim Berezniker

unread,
Mar 16, 2016, 2:21:55 AM3/16/16
to Google Cloud SQL discuss
Do you see anything in /var/log/audit/audit.log when you load the page?

To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/519fa903-49db-4800-93db-31abb918606c%40googlegroups.com.

wob...@yblew.com

unread,
Mar 16, 2016, 6:08:39 AM3/16/16
to Google Cloud SQL discuss
No, I don't see nothing...did it work for you?
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

Vadim Berezniker

unread,
Mar 16, 2016, 2:42:45 PM3/16/16
to Google Cloud SQL discuss
I ran into issues with SELinux blocking apache from opening the sockets, but if you don't see anything in the audit log then it sounds like a different issue.
Did you disable SELinux enforcement?

To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/bbf00a38-96ac-4509-ae11-0edc590f7954%40googlegroups.com.

wob...@yblew.com

unread,
Mar 16, 2016, 2:44:16 PM3/16/16
to Google Cloud SQL discuss
selinux is disabled by default on my system
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

wob...@yblew.com

unread,
Mar 16, 2016, 4:45:58 PM3/16/16
to Google Cloud SQL discuss
So after you disabled Selinux it worked for you?

Vadim Berezniker

unread,
Mar 16, 2016, 5:07:10 PM3/16/16
to Google Cloud SQL discuss
No, I see the same problem. I filed an issue to investigate: https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/7
Can you use the non-fuse mode as a workaround until the issue is resolved?

On Wed, Mar 16, 2016 at 1:46 PM <wob...@yblew.com> wrote:
So after you disabled Selinux it worked for you?

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/58c2ac04-1a5e-4c47-91fc-2d3fa3116925%40googlegroups.com.

wob...@yblew.com

unread,
Mar 17, 2016, 12:48:22 AM3/17/16
to Google Cloud SQL discuss
It seems the only thing stable is below, however it seems I have to assign all databases in mysql to dev@'cloudsqlproxy~%' user before I can see interact with database through the proxy via non socket which is weird; can you confirm? I checked developmentDB.json and it's an editor of all my insitances. If I remember correctly, Kevin said I don't have to assign dev@'cloudsqlproxy~%' to anything, just create it and i'm all set. 

sudo ./cloud_sql_proxy -dir=/cloudsql -instances=my-project:us-central1:sql-inst=tcp:3308 -credential_file=/root/developmentDB.json &

I also tried below for php/mysqli and got permission denied on the browser but it worked for php/pdo in browser

./cloud_sql_proxy -dir=/cloudsql -instances=my-project:us-central1:sql-inst &
mysql -u <user_name> -S /
cloudsql/my-project:us-central1:sql-inst

On Wednesday, March 16, 2016 at 5:07:10 PM UTC-4, Vadim Berezniker wrote:
No, I see the same problem. I filed an issue to investigate: https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/7
Can you use the non-fuse mode as a workaround until the issue is resolved?

On Wed, Mar 16, 2016 at 1:46 PM <wob...@yblew.com> wrote:
So after you disabled Selinux it worked for you?

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

wob...@yblew.com

unread,
Mar 17, 2016, 7:44:56 AM3/17/16
to Google Cloud SQL discuss
To add to my previous question, below is the question I asked and answer I got from Kevin in our previous interaction 

Kevin Malachowski

unread,
Mar 22, 2016, 2:55:19 PM3/22/16
to google-cloud...@googlegroups.com
Sorry for the delay.

I'm a little confused by your question but I'll try to answer what I think you're asking. Feel free to ask again if I missed the mark.

If you create a user dev@'cloudsqlproxy~%' in a database named 'sql-inst' in 'us-central1' in the project 'my-project', then you can connect to that instance using the following 'mysql' command (while the proxy is running on that machine):

mysql -u dev -S /cloudsql/my-project:us-central1:sql-inst

The user that has the 'cloudsqlproxy~%' hostname is the one you want to provide as the '-u' flag (short for --user).

For your PHP/PDO script, it appears that the second parameter of the constructor is the username [0]. In your original post you put 'db' for this value; given a dev@'cloudsqlproxy~%' user, you should use 'dev' instead.


On Wed, Mar 16, 2016 at 9:48 PM, <wob...@yblew.com> wrote:
It seems the only thing stable is below, however it seems I have to assign all databases in mysql to dev@'cloudsqlproxy~%' user before I can see interact with database through the proxy via non socket which is weird; can you confirm? I checked developmentDB.json and it's an editor of all my insitances. If I remember correctly, Kevin said I don't have to assign dev@'cloudsqlproxy~%' to anything, just create it and i'm all set. 

sudo ./cloud_sql_proxy -dir=/cloudsql -instances=my-project:us-central1:sql-inst=tcp:3308 -credential_file=/root/developmentDB.json &

I also tried below for php/mysqli and got permission denied on the browser but it worked for php/pdo in browser

./cloud_sql_proxy -dir=/cloudsql -instances=my-project:us-central1:sql-inst &
mysql -u <user_name> -S /
cloudsql/my-project:us-central1:sql-inst

On Wednesday, March 16, 2016 at 5:07:10 PM UTC-4, Vadim Berezniker wrote:
No, I see the same problem. I filed an issue to investigate: https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/7
Can you use the non-fuse mode as a workaround until the issue is resolved?

On Wed, Mar 16, 2016 at 1:46 PM <wob...@yblew.com> wrote:
So after you disabled Selinux it worked for you?

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-d...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-cloud-sql-discuss/AsVdpcRF5gA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-cloud-sql-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/b9f94b0d-6647-4ca4-9892-ae818f17cdeb%40googlegroups.com.

Marcelo Barreto

unread,
Jun 15, 2016, 12:22:47 PM6/15/16
to Google Cloud SQL discuss
Hi Guys. I`m trying to start cloud proxy with startup script in instance, or startup script in /etc/init.d or even with cron but I can´t.
But if I try to execute those scripts manually I could start cloud proxy. In that scripts I invoke command with full path to cloud_sql_proxy script.
Do you test in Centos startup scripts?
What could be the problem with those scripts?
Thanks in advance.


El martes, 22 de marzo de 2016, 15:55:19 (UTC-3), Kevin Malachowski escribió:
Sorry for the delay.

I'm a little confused by your question but I'll try to answer what I think you're asking. Feel free to ask again if I missed the mark.

If you create a user dev@'cloudsqlproxy~%' in a database named 'sql-inst' in 'us-central1' in the project 'my-project', then you can connect to that instance using the following 'mysql' command (while the proxy is running on that machine):

mysql -u dev -S /cloudsql/my-project:us-central1:sql-inst

The user that has the 'cloudsqlproxy~%' hostname is the one you want to provide as the '-u' flag (short for --user).

For your PHP/PDO script, it appears that the second parameter of the constructor is the username [0]. In your original post you put 'db' for this value; given a dev@'cloudsqlproxy~%' user, you should use 'dev' instead.

On Wed, Mar 16, 2016 at 9:48 PM, <wob...@yblew.com> wrote:
It seems the only thing stable is below, however it seems I have to assign all databases in mysql to dev@'cloudsqlproxy~%' user before I can see interact with database through the proxy via non socket which is weird; can you confirm? I checked developmentDB.json and it's an editor of all my insitances. If I remember correctly, Kevin said I don't have to assign dev@'cloudsqlproxy~%' to anything, just create it and i'm all set. 

sudo ./cloud_sql_proxy -dir=/cloudsql -instances=my-project:us-central1:sql-inst=tcp:3308 -credential_file=/root/developmentDB.json &

I also tried below for php/mysqli and got permission denied on the browser but it worked for php/pdo in browser

./cloud_sql_proxy -dir=/cloudsql -instances=my-project:us-central1:sql-inst &
mysql -u <user_name> -S /
cloudsql/my-project:us-central1:sql-inst

On Wednesday, March 16, 2016 at 5:07:10 PM UTC-4, Vadim Berezniker wrote:
No, I see the same problem. I filed an issue to investigate: https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/7
Can you use the non-fuse mode as a workaround until the issue is resolved?

On Wed, Mar 16, 2016 at 1:46 PM <wob...@yblew.com> wrote:
So after you disabled Selinux it worked for you?

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-cloud-sql-discuss/AsVdpcRF5gA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

Omar Robinson

unread,
Jul 27, 2016, 1:00:57 AM7/27/16
to Google Cloud SQL discuss, wob...@yblew.com
I am having the same issue. I followed all the instructions on this page https://cloud.google.com/sql/docs/compute-engine-access and I am able to connect with mysql -u root -p -S /cloudsql/projectid:region:instance and confirm with show databases;. Now my issue when I connect with the PDO I get :

SQLSTATE[HY000] [2002] Permission denied

The DSN I am trying to connect with is mysql:unix_socket=/cloudsql/<projectid>:<region>:<instance>;dbname=<dbname>;charset=utf8. 

How did you get this to work? I am trying to get this to work with PDO. I am using CentOS.

Thanks


On Monday, March 14, 2016 at 5:20:44 PM UTC-4, wob...@yblew.com wrote:
I double checked and it's still not working. I can connect to it using mysql on the command line but not via PHP/PDO

On Monday, March 14, 2016 at 4:41:10 PM UTC-4, Vadim Berezniker wrote:
Can you double check the instance connection string?
You should use the value that is shown as the "instance connection string" on the instance page in the Developer Console.

instance_name.png

On Mon, Mar 14, 2016 at 9:48 AM <wob...@yblew.com> wrote:
 sudo ./cloud_sql_proxy -dir=/cloudsql -fuse -credential_file=/root/developmentDB.json &
[1] 31266
[root@dev /]# 2016/03/14 12:46:39 couldn't unmount fuse directory "/cloudsql": &errors.errorString{s:"exit status 1: fusermount: failed to unmount /cloudsql: Invalid argument"}
2016/03/14 12:46:39 Mounting "/cloudsql"...
2016/03/14 12:46:39 Mounted "/cloudsql"
2016/03/14 12:46:39 Socket prefix: /cloudsql



On Monday, March 14, 2016 at 12:40:43 PM UTC-4, Vadim Berezniker wrote:
What is the command you are using to start the proxy?

On Mon, Mar 14, 2016 at 9:31 AM <wob...@yblew.com> wrote:
ls /cloudsql give me README.

I changed the socket name to "project_id:region:instance_name. " but no luck 

On Monday, March 14, 2016 at 12:25:13 PM UTC-4, Vadim Berezniker wrote:
Where are you running your application? On your local machine?

The socket name should be project_id:region:instance_name. 
You should be able to run "ls /cloudsql" and see the sockets there.

On Mon, Mar 14, 2016 at 9:19 AM <wob...@yblew.com> wrote:
I tried to connect  to database in  PHP using PDO and Cloud SQL Proxy but have no luck. I keep getting 



Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory'

Im using

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
$pdo = new PDO('mysql:unix_socket=/cloudsql/<your-project-id>:<your-instance-name>;dbname=db', 
'db', 
'db'
);
$statement = $pdo->query("SHOW TABLES;");
$row = $statement->fetch(PDO::FETCH_ASSOC);
echo htmlentities($row['_message']);
?>

Has anyone had any luck connecting

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages