Google Cloud

Java – Configure MySQL for Google Appengine (Standard)

In this post, you will learn about how to configure MySQL properties in your Spring Boot application for deploying it on Google AppEngine (Standard) environment. This article assumes that the MySQL database is set up as part of Google Cloud SQL fully-managed database service. The following will be covered:

  • Configuration properties in Application.properties
  • Configure POM entries in pom.xml file

Configuration properties in Application.properties

In application.properties file, while working with Spring Boot app with JPA repository, you need to have following configuration properties in application.properties file. The below assumes that you have a MySQL database with name as dbname and username/password as root/root.

spring.cloud.gcp.sql.database-name=dbname
spring.cloud.gcp.sql.instance-connection-name=dbname:region:instance-id
spring.cloud.gcp.sql.database-type=mysql
spring.datasource.username=someUsername
spring.datasource.password=somePassword

In above properties, the instance connection name can be obtained from the project Cloud SQL page whose link could look like https://console.cloud.google.com/sql/instances?project=projectName

While working in local environment, you could comment above properties and use the following:

spring.datasource.url=jdbc:mysql://localhost:3306/dbname
spring.datasource.username=root
spring.datasource.password=root

POM entry in POM.xml file

The following POM entry needs to be put in pom.xml file.

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-gcp-starter-sql</artifactId>
    <version>1.0.0.M1</version>
</dependency>

While working in the local environment, one could comment above and rather use following POM entry:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <scope>runtime</scope>
</dependency>

References

Summary

In this post, you learned about how to configure MySQL properties in Spring Boot app for deploying it on Google App Engine (Standard) environment.

Did you find this article useful? Do you have any questions or suggestions about this article? Leave a comment and ask your questions and I shall do my best to address your queries.

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. For latest updates and blogs, follow us on Twitter. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking. Check out my other blog, Revive-n-Thrive.com

Recent Posts

Autoencoder vs Variational Autoencoder (VAE): Differences

Last updated: 08th May, 2024 In the world of generative AI models, autoencoders (AE) and…

1 day ago

Linear Regression T-test: Formula, Example

Last updated: 7th May, 2024 Linear regression is a popular statistical method used to model…

2 days ago

Feature Engineering in Machine Learning: Python Examples

Last updated: 3rd May, 2024 Have you ever wondered why some machine learning models perform…

6 days ago

Feature Selection vs Feature Extraction: Machine Learning

Last updated: 2nd May, 2024 The success of machine learning models often depends on the…

1 week ago

Model Selection by Evaluating Bias & Variance: Example

When working on a machine learning project, one of the key challenges faced by data…

1 week ago

Bias-Variance Trade-off in Machine Learning: Examples

Last updated: 1st May, 2024 The bias-variance trade-off is a fundamental concept in machine learning…

1 week ago