简体   繁体   中英

Using the google.cloud.sql.connector Python library in Python

I'm trying to upload a CSV file to a database in my SQL instance on Google Cloud SQL, and I'm confused as to how exactly am I supposed to go about this project.

my code so far:

import pandas as pd
from google.cloud.sql.connector import connector

read_file = pd.read_csv(PATH TO CSV FILE)
df = pd.DataFrame(read_file, columns=['date', 'current_market_queries',
                                      'last_year_market_queries'])

conn = connector.connect("project:region:instance", "pymysql",
                         host="34.101.244.253", db="insights", user="...",
                         password="...", check_hostname=False)

What exactly are the parameters for the connect method? What's google standard? Is the user supposed to be the email of my Google Cloud account?

Furthermore, is there a link to a website that lists the methods of this google.cloud.sql.connector Python library?

Thanks for the question! Currently, most of our documentation is in the project README and on this Google Cloud documentation page . The user in the connect method will be a user in your Cloud SQL database. This can be an email if you have IAM authentication enabled, but in most cases it will just be the user and password you use to authenticate into the database.

The connect method returns a DB-API 2.0 connection object which can be used to insert each row of your pandas dataframe.

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