26

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?

8 Answers 8

25

Google recently announced support for Cloud SQL in GAE - http://googleappengine.blogspot.com/2011/10/google-cloud-sql-your-database-in-cloud.html

Sign up to request clarification or add additional context in comments.

Comments

20

You cannot create a direct network connection to your database. The overview page outlines 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.

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.

3 Comments

I would really like to know how this answer deserves a downvote, especially a year after the fact.
This is not true anymore. Check out Google Cloud SQL: code.google.com/apis/sql/docs/developers_guide_java.html
@lukas note that you still cannot connect to external MySql databases, like the OP wanted. You are limited to connecting to the App Engine hosted mysql databases. Also, at the moment you can't connect to your cloud hosted database from outside App Engine.
9

The simple answer is : NO.

The way to access your MySQL would be by exposing a web-service interface to it.

1 Comment

thanks for you answer ,did you mean SOAP and RESTful web services here??
4

Look at SDC (Secure Data Connector).

And same question

App Engine and MySQL

Comments

3

Using a Local MySQL Instance During Development:

 

 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");

2 Comments

thanks for providing code , this code works with Local MySQL Instance During Development i want to know is it possible to connect external mysql database(not cloud MySql instance) with app enging(during production)
No. You can use google cloud sql only. This is for security reasons (just they don't give you access to their web services). But you can connect google cloud sql with some desctope client like mysql workbench to manage the google cloud sql on your mashine
1

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.

Comments

1

Yes, you can.

Read about 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.

Comments

0

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

"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

(origionally from App Engine Question)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.