5
votes

Warning: mysql_connect(): MySQL server has gone away in /base/data/home/apps/s~vidaaoblog/wp.372917300827551979/wordpress/wp-includes/wp-db.php on line 1147

Warning: mysql_connect(): Error while reading greeting packet. PID=-1 in /base/data/home/apps/s~vidaaoblog/wp.372917300827551979/wordpress/wp-includes/wp-db.php on line 1147

Warning: mysql_connect(): MySQL server has gone away in /base/data/home/apps/s~vidaaoblog/wp.372917300827551979/wordpress/wp-includes/wp-db.php on line 1147

Getting these errors with everything.

WP_CONFIG:

define('DB_NAME', 'wordpress_db');

/** MySQL database username */
define('DB_USER', 'wp_user');

/** MySQL database password */
define('DB_PASSWORD', 'wp_password');

/** MySQL hostname */
if(isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'],'Google App Engine') !== false) {
  define('DB_HOST', ':/cloudsql/YOUR_PROJECT_ID:INSTANCT_ID');
}else{
  define('DB_HOST', '127.0.0.1');
}

Followed these instructions: https://developers.google.com/appengine/articles/wordpress

the google cloud instance run on a separate project but the app is allowed to access

3
you did change YOUR_PROJECT_ID:INSTANCT_ID right? - Spikolynn
I have the same problem. It works locally, but not when deployed. I have followed the instructions carefully. DB_HOST is set dynamically, according to instructions. - Per Quested Aronsson
APP_ENGINE_SDK_PATH/appcfg.py update APPLICATION_DIRECTORY have you tried running step 8? - RGAT
I'm not sure if these will help but a quick google search got me googlecloudplatform.github.io/… and developers.google.com/appengine/articles/wordpress which if not already known may be of some help. - therons

3 Answers

1
votes

If you are migrating your WP to GCE w/Cloud SQL, you should:

  1. Create a cloud storage bucket & upload your mysqldump file (with --hex-blob condition).
  2. Create a cloud SQL instance + create a root password (no password by default).
  3. Import the *.sql (or gzip) file up into the database.
  4. Create a [WordPress] user with privileges to that db access within that cloud sql instance.
  5. Pre-authorize GCE instance access to the Cloud SQL instance, by static IP, or ephemeral IP [CIDR format].
  6. Depending on your [WP] GCE server flavor (e.g. debian), install mysql-client.
  7. Create a Cloud SQL IPv4 address.
  8. Copy the address into your WP config.php file, like: define('DB_HOST', 'xx.xx.xxx.xxx:3306');

Your WP site should establish the database connection on the next page refresh.

0
votes

Make sure your app engine instance and Cloud SQL instance is set to the same region.

By default, app engine is set to United States.

Lastly, check that you've authorised your app engine app in your Cloud SQL instance.

0
votes

The google app engine documentation states

"Google Cloud Platform project called is connecting to a Cloud SQL instance named ."

you are probably getting an error because for project id you are using the project Id for your appengine application not your Cloud SQL project ID. so try:

$db = new pdo('mysql:unix_socket=/cloudsql/<sql-project-id>:<sql-instance-name>;dbname=<db-name>', 'root', '');