简体   繁体   中英

R Shiny can't connect to MySQL database hosted on GCP

I can access the database if I run the app from my local machine without problems, but after deployment on shinyapps.io, I get an error ("The application failed to start."). I suppose that I need to change to host IP from localhost to something else, but the IP address of my database instance does not work either.

pool<- dbPool(
  drv = RMySQL::MySQL(),
  dbname = 'XXXXXX', 
  username = 'XXXXXX',
  password = 'XXXXXX',
  host = '127.0.0.1',
  port = 3307
)

For the local connection, I use Cloud SQL Proxy.

  1. Any ideas how the app could connect to the database from the Shiny Server?
  2. How can I account for both the local machine's connection and the cloud-to-cloud connection in my code?

This question is similar but without Cloud hosting: Error to connect to database (Mysql) when publising shiny app

To connect to your Cloud SQL instance using public ip, the IP address of your Shiny server where your app is deployed must configured as an authorized network

You may check this link on how to configure authorized networks and connect your Cloud SQL instance using public ip address.

Note: If you're going to deploy your application, you may need to modify the host IP and use your sql instance public ip address in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM