我可以在 App Engine 应用程序中使用 MySQL 数据库吗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1651629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I use a MySQL database with an App Engine application
提问by GPollice
I know that App Engine has its own datastore. This is great for most cases and fairly easy to used. However, we have a MySQL database that we use for several applications and not all of them are Web based. We want to use App Engine for many reasons, but would like to have the App Engine application access our MySQL database. The documentation I've found doesn't clearly state whether I can do this or not. Has anyone done it or have pointers to documents that show how to do it?
我知道 App Engine 有自己的数据存储。这对大多数情况来说都很好,而且相当容易使用。但是,我们有一个用于多个应用程序的 MySQL 数据库,并非所有应用程序都是基于 Web 的。我们出于多种原因想要使用 App Engine,但希望 App Engine 应用程序访问我们的 MySQL 数据库。我找到的文档没有明确说明我是否可以这样做。有没有人做过或有指向显示如何做的文件的指针?
回答by Uday Shanmugam
Google recently announced support for Cloud SQL in GAE - http://googleappengine.blogspot.com/2011/10/google-cloud-sql-your-database-in-cloud.html
Google 最近宣布在 GAE 中支持 Cloud SQL - http://googleappengine.blogspot.com/2011/10/google-cloud-sql-your-database-in-cloud.html
回答by Peter Recore
You cannot create a direct network connection to your database. The overview pageoutlines the major restrictions that would stop you from using Mysql - the major one in this case being "arbitrary network connections". You can only make http(s) calls from within app engine.
您无法创建到数据库的直接网络连接。在概述页面列出了主要的限制会阻止你使用MySQL -主要一个在这种情况下,被“任意网络连接”。您只能从应用引擎内进行 http(s) 调用。
The JVM runs in a secured "sandbox" environment to isolate your application for service and security. The sandbox ensures that apps can only perform actions that do not interfere with the performance and scalability of other apps. For instance, an app cannot spawn threads, write data to the local file system or make arbitrary network connections. An app also cannot use JNI or other native code. The JVM can execute any Java bytecode that operates within the sandbox restrictions.
JVM 在安全的“沙箱”环境中运行,以隔离您的应用程序以获得服务和安全性。沙箱确保应用程序只能执行不会干扰其他应用程序的性能和可扩展性的操作。例如,应用程序不能产生线程、将数据写入本地文件系统或进行任意网络连接。应用程序也不能使用 JNI 或其他本机代码。JVM 可以执行在沙箱限制内运行的任何 Java 字节码。
回答by jldupont
The simple answer is : NO.
简单回答是不。
The way to access your MySQL would be by exposing a web-service interface to it.
访问 MySQL 的方法是向它公开 Web 服务接口。
回答by Manjoor
回答by makkasi
Using a Local MySQL Instance During Development:
在开发过程中使用本地 MySQL 实例:
import com.google.appengine.api.rdbms.AppEngineDriver; public static void makeConnection() { try { if (conn == null || !conn.isValid(0)) { String url = "localhost/databasename"; String username = "root"; String password = "password"; DriverManager.registerDriver(new AppEngineDriver()); String urlForConnection = "jdbc:mysql://" + url; conn = DriverManager.getConnection(urlForConnection, username, password); } } catch (SQLException e) { e.printStackTrace(); } } // in web.xml <filter> <filter-name>_ah_DevSocketFilter</filter-name> <filter-class>com.google.appengine.api.socket.dev.DevSocketFilter</filter-class> <init-param> <param-name>use-native-sockets</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>_ah_DevSocketFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
Using cloud
使用云
DriverManager.registerDriver(new AppEngineDriver());
c = DriverManager.getConnection("jdbc:google:rdbms://instance_name/guestbook");
回答by Simon
Yes, but not the normal, by creating a web service or a simple php page that acts as an intermediate and passing the data in json or xml.
是的,但不是正常的,通过创建一个 web 服务或一个简单的 php 页面作为中间人和传递 json 或 xml 中的数据。
回答by VarthDaver
I am still in the learning phase of all this, but I am fairly certain you can do this now a few ways:
我仍处于所有这些的学习阶段,但我相当确定您现在可以通过以下几种方式做到这一点:
- Link Apps Scripts to App Engine and use the JDBC and ink it to Google
- Store your SQL database on Google Cloud Storage
- Connect Apps Scripts via spreadsheet scripting
- Use their Cloud SQL
- 将 Apps 脚本链接到 App Engine 并使用 JDBC 并将其链接到 Google
- 将您的 SQL 数据库存储在 Google Cloud Storage 上
- 通过电子表格脚本连接 Apps 脚本
- 使用他们的 Cloud SQL
"Google Apps Script has the ability to make connections to databases via JDBC with the Jdbc Service. The current support extends to MySQL, Microsoft SQL Server and Oracle. Apps Script makes it easy to connect to databases hosted on Google Cloud SQL, but also works with other cloud hosting platforms and even local databases." https://developers.google.com/apps-script/jdbc
“Google Apps Script 能够使用 Jdbc 服务通过 JDBC 连接到数据库。当前支持扩展到 MySQL、Microsoft SQL Server 和 Oracle。Apps Script 可以轻松连接到托管在 Google Cloud SQL 上的数据库,但也可以正常工作与其他云托管平台甚至本地数据库。” https://developers.google.com/apps-script/jdbc
(origionally from App Engine Question)
(最初来自App Engine 问题)
回答by Tiago Gouvêa
Yes, you can.
是的你可以。
Read about int https://cloud.google.com/sql/docs
阅读关于 int https://cloud.google.com/sql/docs
You can use it with any language supported by GAE and connect over it from outside GAE too.
您可以将它与 GAE 支持的任何语言一起使用,也可以从 GAE 外部通过它进行连接。