google-cloud-platformgoogle-cloud-sqlgoogle-cloud-run

When the Cloudsql restarted, all the Cloudrun service stops working


When the Cloudsql restarted, all the Cloudrun services linked to the Cloudsql(Database version is MySQL 8.4.4) stops working. with below error

Fatal error: Uncaught mysqli_sql_exception: Access denied for user 'user'@'cloudsqlproxy-34-96-47-98' (using password: YES) in /var/www/opencart/system/library/db/mysqli.php:7 Stack trace: #0 /var/www/opencart/system/library/db/mysqli.php(7): mysqli->_construct(NULL, 'xxxx...', Object(SensitiveParameterValue), 'yyyyy...', '3306', '/cloudsql/iamre...') #1 /var/www/opencart/system/library/db.php(33): DB\MySQLi->_construct('/cloudsql/iamre...', 'db_name...', 'pwd...', 'db_name...', '3306') #2 /var/www/opencart/system/framework.php(82): DB->_construct('mysqli', '/cloudsql/iamre...', 'vvvvv...', 'pwd...', 'trial965_db_08...', '3306') #3 /var/www/opencart/system/startup.php(104): require_once('/var/www/openca...') #4 /var/www/opencart/index.php(19): start('catalog') #5 {main} thrown in /var/www/opencart/system/library/db/mysqli.php on line 7

The most weird that it gets resolved when we login to CloudSQL Studio using the DB creds configured in the Cloudrun service. After login to each DB one by one using CloudSQL Studio, respective cloudrun service starts working fine.

enter image description here

Instantly after we manually login to the CloudSQL Studio the Cloudrun service can able to make the connection to the DB. Unable to understand that is the relation between SQL Studio > Login and CloudRun access to the DB.


Solution

  • This is a known issue and as of April 2025 we are working on it. Mysql 8.4 introduced a new password strategy called "caching_sha2_password". Cloud Run uses the Cloud SQL Auth Proxy to the Cloud SQL database. There is a bug in the Auth Proxy (and other connectors too) that breaks the caching_sha2_password protocol. The login starts working again after you log in with Cloud SQL Studio because the authentication is cached in Cloud SQL instance for a period of time.

    We are tracking the bug here and actively working on a fix. See Cloud SQL Proxy #2317

    At the moment, your best work-around is to downgrade to Mysql 8.0.