DB_HOST

488 views
Skip to first unread message

Salim Karim

unread,
Oct 17, 2016, 9:45:43 AM10/17/16
to Google Cloud SQL discuss
hi,

i am trying to run Wordpress with Cloud SQL.

I need to know what the DB_HOST should say?

currently it is set to the IP of Cloud SQL but I get 'redirected you too many times.'




Did you receive      service?
Feel free to leave a Google Review
Not Happy? Please contact our CEO


Connect with us: 

    

Please consider the environment before printing this email.

 

This e-mail and any attachments to it (the "Communication") is, unless otherwise stated, confidential,  may contain copyright material and is for the use only of the intended recipient. If you receive the Communication in error, please notify the sender immediately by return e-mail, delete the Communication and the return e-mail, and do not read, copy, retransmit or otherwise deal with it. Any views expressed in the Communication are those of the individual sender only, unless expressly stated to be those of National Training and Solutions Provider Pty Ltd ABN 34 123 831 023, or any of its related entities. NTSP does not accept liability in connection with the integrity of or errors in the Communication, computer virus, data corruption, interference or delay arising from or in respect of the Communication.

Alex (Cloud Platform Support)

unread,
Oct 17, 2016, 4:42:53 PM10/17/16
to Google Cloud SQL discuss

Hi Salim,


Depending on your environment, you have several options available to you in the following link for connecting to your Cloud SQL instance. As in the subsection “Configure access to your Cloud SQL instance”, you may have to authorise the IP address of the client machine where your MySQL client is installed.


To answer your question about setting up the DB_HOST variable, again depending on your environment(Wordpress site hosted on Google App Engine) you may be able to fix your redirect issue by setting it to ':/cloudsql/[YOUR_PROJECT_ID]:[Instance Region]:[Instance name]' as in the following “Setting up the WordPress project” link.


Alternatively, it is possible that the redirect can be caused by a plugin within the Wordpress environment. In that case, the best remedial action is to test each plugin individually after disabling them all.


In case none of the previous solutions works, please provide the following information about your set up:

- The generation of the Cloud SQL instance that you are using

- Where you are hosting your Wordpress Site

- The exact value of the DB_HOST that you have set

- Which version of MySQL are you using


Let me know if you're able to resolve it and share your setup infos if need more help with connecting to the Cloud SQL instance.

Salim Karim

unread,
Oct 17, 2016, 5:57:39 PM10/17/16
to google-cloud...@googlegroups.com
hi 

thanks for your reply.

i have already authorised my ip hence i dont get the 'error contacting to database'
it's not a appengine project but a compute engine

please note my answers below;

- first gen cloud sql
- hosted on compute engine
- cloud sql ip = 173.194.81.232
- mysql 5.6

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/ad50845f-ebb4-4033-8656-01223eb16ec5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Salim Karim
General Manager

ext. 14

Alex (Cloud Platform Support)

unread,
Oct 19, 2016, 1:29:35 PM10/19/16
to Google Cloud SQL discuss

Hi again,


Thanks for providing details about your environment. Still, I was unable to reproduce your error using a similar setup to yours, mainly consisting of a WordPress website hosted on Compute Engine and linked to a MySQL database on Cloud SQL.


For the reproduction, I used the Cloud Launcher to launch a WordPress solution. After importing a “dump.sql” file (from MySQL database of the WordPress Solution) to a first generation Cloud SQL instance, I followed this guide to successfully connect my WordPress website to the transferred database.


Important steps to note:


1. Generate an IPv4 address on both instances(static IPv4 on GCE) and authorise the one form GCE to connect to the Cloud SQL instance.

2. Create a user account on the Cloud SQL instance under the Access Control tab and set the “Host name” to the GCE’s instance static IPv4 or to “Allow any host (%)” for testing purposes.

3. Edit the wp-config.php file in the \var\www\html directory of the Wordpress site on the GCE instance with DB_HOST set to ‘[Cloud SQL Generated IPv4 address]’, and the other variables matching your newly created user and uploaded database name on the Cloud SQL instance.


Note that you can test your Cloud SQL database connection from the GCE instance through SSH on the instance menu and running the GCloud command  “mysql --host=[Cloud SQL Generated IPv4 address] --user=[Created User] --password”. This way you can make sure that the uploaded database on Cloud SQL is reachable after having configured a new user, all the IPv4 addresses and authorisation steps. More information can be found on this link.


Concerning the redirect issue, it may be caused by a misconfigured Apache server and so you may want to use external tools such as this one to identify what is causing it.


Let me know if those tips help you to connect to the Cloud SQL database and if you need any additional clarification.

jinguruxxx

unread,
Jul 25, 2017, 10:12:15 AM7/25/17
to Google Cloud SQL discuss
Hi - i am hoping this forum is still open for posts
I am experiencing a similar problem although not relating to Wordpress

I created a micro VM on Compute engine and created a LAMP stack
I uploaded my script which required an MySQL database created locally. All works fine

I then created 2 instance on Google SQL( First Generation and Second Generation with a database in each.
Following the documentation i set up credentials to allow access as well as making necessary adjustments to phpMyAdmin script so that i can access these databases from 
<myIPaddress>/phpMyAdmin

All good

BUT

Now i am stuck with actually connecting the web page to the remote Google SQL instance+database
I believe I am posting the HOST credentials incorrectly

Credentials are in a config.php file in path in the root folder var/www/html/includes/config.php

normally i have [excerpt]

$CONF = $TMPL = array();

// The MySQL credentials
$CONF['host'] = '"localhost"';
$CONF['user'] = 'username';
$CONF['pass'] = 'pwd';
$CONF['name'] = 'databasename';


i am using 

$CONF['host'] = ':/cloudsql/jinguru-live:europe-west1:jdb-gcpsql-002a';

When i try to load up the webpage i get

Failed to connect to MySQL: (2005) Unknown MySQL server host '":/cloudsql/jinguru-live:europe-west1:jdb-gcpsql-002a"' (2)Error:

Please let me know what i am doing wrong!!
I can provide further details re the Google Compute Engine and Google SQL credentials

THanks

David Newgas

unread,
Jul 25, 2017, 12:09:49 PM7/25/17
to Google Cloud SQL discuss
Hi,

The ":/cloudsql/project:region:id" instructions are for Google App Engine. If you are on Google Compute Engine, you have two options:
  1. Connect to the public IP address of your Cloud SQL instance. This requires you whitelist your GCE instance on the ACL for the Cloud SQL instance.
  2. Use the Cloud SQL proxy. This is a extra daemon you run on your GCE instance that allows you to connect via TCP on localhost or a socket.
Complete instructions for both of these options are available at https://cloud.google.com/sql/docs/mysql/connect-compute-engine.

--
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.

JinGuru

unread,
Jul 25, 2017, 1:24:27 PM7/25/17
to google-cloud...@googlegroups.com
Hi Thank you for the response.

It looks as if i erred!

Will remedy that

To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscr...@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/pgTB5n-kfbo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-cloud-sql-discuss+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/CAJZK_bbC37TaPxabkN5-84_ewOERcBzzsL%3DAZQuQUKS-RK235Q%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages