Connecting to Cloud SQL MySQL

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-02 16:43:00

问题


We would like to test connecting Cloud SQL (mySQL) to BigQuery using Cloud Data Fusion. What is the proper way to connect to CloudSQL as that does not appear to be "build in" at this point in time. What driver is recommended and are there any instructions available?


回答1:


Here are instructions to use Cloud SQL MySQL in Data Fusion. Note that in the Wrangler section, currently, Cloud SQL instances with Private IP cannot be used. However, they can still be used when running Data Fusion pipelines

Using Cloud SQL (MySQL) in Wrangler (Public IP only)

  1. Obtain the JDBC Driver JAR file by building it using the instructions at https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory
  2. Go to Wrangler
  3. If this is the first time you are configuring CloudSQL for MySQL, click on the Add Connection button from the Wrangler screen and choose Database.
  4. Click “Google Cloud SQL for MySQL.”
  5. Upload the previously built JAR as illustrated, and click the Next button.
  6. Click the Finish button to complete the upload.
  7. Once the driver has been uploaded you will see a green check mark indicating that your driver has been installed.
  8. Click the Google Cloud SQL for MySQL to create a new connection. Once the connection modal opens click on the Advanced link if present.
  9. Enter connection string as

    jdbc:mysql://google/<database>?cloudSqlInstance=<instance-name>&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false

where represents the database you created in the prerequisites section, and refers to you instance connection name as displayed in the overview tab of of the instance details page, e.g:

Example:

jdbc:mysql://google/mysql?cloudSqlInstance=cloud-data-fusion-demos:us-west1:mysql&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false

  1. Enter the username and the password you configured for this CloudSQL instance
  2. Click Test Connection to verify that the connection can successfully be established with the database.
  3. Click Add Connection to complete the task.
  4. Once you’ve completed all the steps you will be able to click on the newly defined database connection and see the list of tables for that database.

Using Cloud SQL (MySQL) in Pipelines (Public and Private IP)

  1. Perform steps 1-6 in the Wrangler section above
  2. Open the pipeline Studio
  3. From the plugin palette on the left, drop the Cloud SQL source plugin to the canvas, and open it by clicking Properties.
  4. Specify the plugin name as cloudsql-mysql (Presumes that you have perform.
  5. Specify the connection string as below:

    jdbc:mysql://google/?cloudSqlInstance=&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false

where represents the database you created in the prerequisites section, and refers to you instance connection name as displayed in the overview tab of of the instance details page, e.g.:

jdbc:mysql://google/mysql?cloudSqlInstance=cloud-data-fusion-demos:us-west1:mysql&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false
  1. Enter the query that you would like to import data from as the Import Query
  2. Enter the username and password to use for the database. You can also use a secure macro for the password.
  3. Click Get Schema to populate the schema of the plugin.
  4. Configure the rest of the pipeline, and deploy.


来源:https://stackoverflow.com/questions/55856461/connecting-to-cloud-sql-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!