应用程序引擎上的codeigniter连接到mysql时超时

tkqqtvp1  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(331)

我在gcp app engine上托管codeigniter api,无法连接到gcp cloud sql。我创建了示例和数据库,但是当我试图通过ci连接时,我得到了一个超时消息错误屏幕

我在ci上的数据库配置是:

$db['default'] = array(
  'dsn' => 'mysql:unix_socket=/instance_name/instancia;dbname=project_name',
  'hostname' => 'http://00.000.00.00',//here i put the public ip from the sql instance
  'username' => 'user',
  'password' => 'passwd',
  'database' => 'projeto',
  'dbdriver' => 'mysqli',
  'dbprefix' => '',
  'pconnect' => FALSE,
  'db_debug' => (ENVIRONMENT !== 'production'),
  'cache_on' => FALSE,
  'cachedir' => '',
  'char_set' => 'utf8',
  'dbcollat' => 'utf8_general_ci',
  'swap_pre' => '',
  'encrypt' => yes,
  'compress' => FALSE,
  'stricton' => FALSE,
  'failover' => array(),
  'save_queries' => TRUE
);
vltsax25

vltsax251#

我自己在这上面撞了好一阵子,终于把它破解了!我的数据库配置如下:

$db['default'] = array(
  'dsn' => '',
  'hostname' => '/cloudsql/PROJECT-NAME:REGION:DATABASE',
  'username' => 'USERNAME',
  'password' => 'PASSWORD',
  'database' => 'DATABASE_NAME',
  'dbdriver' => 'mysqli',
  'dbprefix' => '',
  'pconnect' => FALSE,
  'db_debug' => (ENVIRONMENT !== 'production'),
  // 'db_debug' => TRUE,
  'cache_on' => FALSE,
  'cachedir' => '',
  'char_set' => 'utf8',
  'dbcollat' => 'utf8_general_ci',
  'swap_pre' => '',
  'encrypt' => FALSE,
  'compress' => FALSE,
  'stricton' => FALSE,
  'failover' => array(),
  'save_queries' => TRUE
);

重要的是dsn是空的,主机名是unix套接字的完整路径。剩下的应该差不多。
希望这对你也有帮助!

相关问题