LoginSignup
6

More than 5 years have passed since last update.

cloud_sql_proxyで接続しようとするとERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0

Posted at

背景

cloud_sql_proxy経由でcloud_sqlに接続する設定をドキュメント見ながらやろうとしたらハマった。
https://cloud.google.com/sql/docs/mysql-connect-proxy?hl=ja

mysql -u user -p -host 127.0.0.1

で接続しようとするとこんなエラーが出る。

ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0

解決策

コンソールのGoogle Cloud SQL APIを有効にする。

コンソールだと

API Manager -> ダッシュボード -> APIを有効にする -> 「cloud sql api」 で検索 -> 有効にするをクリック

もしくは、

https://console.developers.google.com/apis/api/sqladmin/overview?project=<project_id> 
のページにいって「APIを有効にする」をポチる。

有効にしてから数分後アクセスできるようになる。

以上。

バックグラウンドで起動していて、以下のログを見逃していたのがハマった原因。

2017/02/22 08:53:40 couldn't connect to "project_id:asia-northeast1:xxxxx": ensure that the account has access to "project_id:asia-northeast1:xxxxx" (and make sure there's no typo in that name). Error during createEphemeral for project_id:asia-northeast1:xxxxx: googleapi: Error 403: Access Not Configured. Cloud SQL Administration API has not been used in project 297993258130 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sqladmin/overview?project=xxxxx then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry., accessNotConfigured

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6