简体   繁体   English

在 Pycharm 中使用 Python 将数据从 CSV 文件上传到 Google Cloud SQL 实例

[英]Uploading Data from a CSV file to a Google Cloud SQL Instance using Python in Pycharm

I am having trouble figuring out how to upload data from a CSV file to an SQL instance on Google Cloud.我无法弄清楚如何将数据从 CSV 文件上传到 Google Cloud 上的 SQL 实例。 The scope of my project right now is to collect data from a website, import it into a CSV file, and then upload the data from the CSV file into my Cloud SQL instance, all automated by Python.我现在的项目范围是从网站收集数据,将其导入 CSV 文件,然后将 CSV 文件中的数据上传到我的 Cloud SQL 实例,所有这些都由 Python 自动化。 My IDE where I write my code in is in Pycharm, so I was wondering if it's possible to have Python handle everything- are there any necessary Python libraries that I have to import?我在其中编写代码的 IDE 是在 Pycharm 中,所以我想知道是否可以让 Python 处理所有事情——是否有任何我必须导入的必要 Python 库?

Yes you can do all of this in python.是的,你可以在 python 中完成所有这些。 There's 3 things to do here.这里有 3 件事要做。

  1. Use a package to get the data from 'a website'.使用包从“网站”获取数据。 Depending on the website, just using the requests package might be enough.根据网站的不同,仅使用 requests 包可能就足够了。 Otherwise you might need to dip into a more 'complicated' package like beautifulsoup .否则,您可能需要使用更“复杂”的包,例如beautifulsoup
  2. Using the method above you'll need to put this in a CSV file.使用上述方法,您需要将其放入 CSV 文件中。 I'm not sure why you would want to use a CSV file as an intermediary here, but there's a ton of tutorials on handling CSV files.我不确定您为什么要在这里使用 CSV 文件作为中介,但是有大量关于处理 CSV 文件的教程。
  3. Use a SQL package to read/write to the Cloud SQL instance.使用 SQL 包读取/写入 Cloud SQL 实例。 The w3 page for MySQL is a good starting point. MySQL 的w3 页面是一个很好的起点。

Also, read up on how to connect from whereever you're running your code to a Cloud SQL instance.此外,请阅读有关如何从运行代码的任何位置连接到 Cloud SQL 实例的信息。 I very strongly advise to use the Cloud SQL proxy as described in this article .我非常强烈建议中所述使用云SQL代理这篇文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 python 将 CSV 从谷歌云上传到 Bigquery - Uploading CSV from google cloud to Bigquery using python 使用Python将文件从Google云端存储上传到Bigquery - Uploading a file from Google Cloud Storage to Bigquery using Python 在pycharm中上传pandas python中的csv文件 - uploading a csv file in pandas python in pycharm 在 Cloud Run 实例中从 Cloud Storage 访问和使用 csv 文件 - Accessing and using csv file from Cloud Storage in Cloud Run instance 使用 Python 从 ServiceNow 实例将数据导出为 CSV 文件 - Exporting data as CSV file from ServiceNow instance using Python 使用 python request.put 上传 csv 类型数据而不读取保存的 csv 文件? - Uploading a csv type data using python request.put without reading from a saved csv file? 使用 python 将文件上传到 Google 云平台上的存储桶时出现问题 - Issue when uploading a file to a bucket on Google cloud platfrom using python 使用Python在Google Cloud Storage存储桶中创建/上传新文件 - Creating/Uploading new file at Google Cloud Storage bucket using Python 有没有办法通过 python 中的 REAST API 从 Google SQL 云中转储表数据(json 或 csv)? - Is there a way to dump a table data (json or csv) from the Google SQL Cloud via a REAST API in python? 使用 Python 将 CSV 文件上传到 Google Cloud Storage - Upload CSV file to Google Cloud Storage using Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM