Updating a Google Cloud SQL Database instance - php

I have a deployed Cloud SQL Database instance running right now and it works fine. I am able to access and use it via my PHP Google App Engine app. I also have a local SQL Database for development.
Locally, I have made some changes to the structure of the database (added new columns) and would like to push those changes to the deployed app.
When I try to do this via the documented method on the App Engine site, I get an error saying the import failed for an unknown reason.
I am using a .sql dump made by PhpMyAdmin and have done this successfully for the initial import. I made sure to include USE DATABASE NAME in the dump.
Any ideas as to why it's failing? What is the best way to update a Cloud SQL Database? Thanks a lot!

An easy way is to request an IP, whitelist the IP you are connecting from (link) and use the MySQL client (link). Over IP you can also use GUI tools like MySQL Workbench, Toad, SQuirrel SQL and others (link).

You can set up phpMyAdmin as a different version of your application using the instructions here: https://gae-php-tips.appspot.com/2013/05/26/setting-up-phpmyadmin-on-app-engine/ That would probably be the easiest way of updating a Cloud SQL database...

Related

Working locally on an existing remote Laravel project linked with a database

I have recently joined a project that uses AWS EC2 to deploy a frontend in NodeJS and a backend in Laravel linked to a phpMyAdmin database. My question is simple but I have not found the way to do it despite litteral hours of research.
How can I launch the backend locally and use the corresponding database?
I should add that the database seems to be automatically generated by the Laravel backend and it contains a folder of "mutations".
I am relatively new to php, VMs and Linux overall.
Thank you for your help
This project is probably using mysql or mariadb as database engine.
You must install the engine and export all of data from server and import it in your local database.
If database is on server and you want to connect to that database, it depends on security mechanisms. You must expose the db engine's port in the server and changing your laravel config to use that host for database connection. But I don't recommend that!
If you just want to run backend for personal tests, just setup backend and database engine and run migrations. I can't help you with this step cause I don't know how are deploy operations in your team. If you provide more information, we can help better.

Laravel MySQL Google App Engine - ERROR: (gcloud.sql.instances.describe) There was no instance found

I deployed my Laravel 5.6 application using Google App Engine following these steps. The Laravel app is live at a URL but I am having trouble getting MySQL set up.
I created a 2nd generation MySQL development database, then installed the Cloud SQL Proxy client on my macbook. When I try to connect to the instance I get an error that no instance was found. What am I doing wrong?
Here are the commands I ran to get my app started
$ gcloud init
$ gcloud app deploy
$ gcloud app browse
$ curl -o cloud_sql_proxy https://dl.google.com/cloudsql/cloud_sql_proxy.darwin.amd64
$ chmod +x cloud_sql_proxy
$ gcloud sql instances describe laraveljwtstarter
ERROR: (gcloud.sql.instances.describe) There was no instance found at
projects/laraveljwtstarter/instances/laraveljwtstarter or you are not
authorized to access it.
My instance is named laraveljwtstarter that I created through the Google Cloud Platform UI. How can I connect my Laravel app to this database?
Well, first of all you are not connecting to the instance with the commands that you have shared.
gcloud sql instances describe laraveljwtstarter - this command simply displays configuration and metadata about a Cloud SQL instance named laraveljwtstarter. As it has already been mentioned above, please make sure that the database is created before running that command and make sure you are specifying the correct database name.
If you wish to connect to the database using the Cloud SQL Proxy, you will have to first off start it up like it says in the article you mentioned. As far as I understood, you have an application in App Engine, therefore you are using the wrong example from the documentation. Generally, if you want to connect your GAE app with the Cloud SQL instance, there is a number of options, depending if you are using App Engine Standard environment or Flexible environment. Both options are available for PHP and you can read more here.
Normally you use the Cloud SQL Proxy because it provides secure access to your Cloud SQL Second Generation instances without having to whitelist IP addresses from which you will be connecting or having to configure SSL. You will need a Cloud SQL Proxy for your application to connect to the Cloud SQL database locally. For a deployed application there is no need for setting up a Cloud SQL Proxy.
Also, here is a short, but informative video about using Cloud SQL in App Engine.
I know that my answer is broad, but you should post a more specific question to get a specific answer.
Nevermind, just make sure the database created through the UI has actually been created!

Connecting to OpenShift via Device

Good afternoon all;
I am developing an application for a project that utilizes an OpenShift MySQL Database. At the moment, I have written php scripts that ping the database on our host website, which, is also hosted on OpenShift.
My fear is that anyone can call this php address and either a) DDoS my DB/website, or b) can access or get any data inside said DB. There is nothing highly critical on this database, such as passwords and all, but it's best using best practices.
To my question: Is there a way to directly connect to this DB via various platforms such as iOS, Android, and Desktop (Mac, PC, Linux) and not use php scripts? I am somewhat familiar with OpenShift's PortForwarding, but I believe this is not what I am looking for.
If it is not possible to connect to said DB in this way, is there a way to make this process of getting data from the DB more secure?
Note on my php scripts:
They connect to the DB using a username and password. This user has only select and edit privileges. The purpose is to get fields of data: Building and Amount, and at times changes Amount, based on arguments of the php address. The returned data is encoded using JSON.
Check for NodePort feature in openshift/k8s, that should allow connections if this is a self hosted openshift

Using my php scripts in Android to access database

I need some major help in setting up my android app to add/receive data to/from my database. I'm using Amazon's RDS service in connection with xampp's phpMyAdmin. I've already successfully connected my DB instance to the database in phpMyAdmin. Also, I've written my php scripts to do basic CRUD (Create, Read, Update, Delete) commands in SQL. I've been following this tutorial.
The problem for me is, in his tutorial he is using strings like this:
private static String url_all_products = "http://api.androidhive.info/android_connect/get_all_products.php";
to run his php scripts in a call to makeHttpRequest(url_all_products). But I don't have my own website to do this and I'm pretty sure I don't need one to do this.
Next, I have a test.php file that does a simple echo statement and it works when I run this in a web browser:
http://localhost/phpfiles/test.php
Which leads me to my second problem. I don't want to use localhost because I need these php files and the ability to retrieve data from the database to be accessible to anyone using my app. This is the sole reason I'm using Amazon's RDS service so my database can be accessed on the cloud.
So how can I use the host address provided to me by Amazon RDS to access the database and where do I store all the php files so I can properly use them in Android the way the tutorial shows? They are currently saved in xampp/htdocs/phpfiles/.
I feel like I'm missing some fundamental understanding of all this and I'm going about it all wrong. If someone can point me in the right direction that would make my day.
It sounds like you don't really need the XAMPP install on your local machine at all. You're hosting this on Amazon and you want it to be available to the internet, so your local computer isn't involved. You can use XAMPP locally for testing and development, but for production use you'll be exclusively on the Amazon RDS cloud.
But I don't have my own website to do this and I'm pretty sure I don't need one to do this.
You may not want a website, but you do want your services hosted on the internet. That's what your RDS instance is for, and technically the tutorial is referring to an API which happens to be exposed through a web page. This is a much better idea than opening MySQL directly to the internet on port 3306.
You'll then use your Amazon host — for which you really should use a FQDN such as api.example.com rather than the IP address, but the IP address will work just fine from a technical aspect.
The files you refer to are on your local XAMPP installation; in the xampp/htdocs/phpfiles/ folder, and need to instead be on the RDS instance.
Then your application accesses the API you expose in those files which return information back to your application.

Google Cloud SQL - MySQL server has gone away

I have a site remotely hosted away from the Google Cloud SQL instance. I have set up and authorised CIDR range for this. I am using PHP (PDO) to connect to the Google Cloud SQL instance with an application built on the Laravel 5 framework. The website itself is deployed on Windows Azure, I do not have a choice about this stack.
My problem is on probably about 10% of page loads I receive the error:
SQLSTATE[HY000] [2006] MySQL server has gone away
While trying to set up the CIDR for this in the developer console (getting my Azure IP and converting it to a range) I had this problem 100% of the time, so it's possible that it's related to IP authorisation, however why would this work 80-90% of the time, and deny the application sporadically?
Any help would be much appreciated.
go to the cloud sql instance you created. Under properties you will see "authorized applications" click manage and add the project id of your project to it. hope that works for you
I know this is old, but in case someone else ran into similar problems like I did, this might help...
Check your system clock, make sure it's not behind (happened to me with a local docker instance)
Check your credentials to make sure they're correct and match up with the instance you're trying to connect to.
Good luck

Categories