Friday, March 29, 2024

Setting up Google Cloud SQL

You can activate Google Cloud SQL from the Google APIs Console at https://code.google.com/apis/console. NOTE: At the time of this publication this was in limited beta.

From the Google APIs console, you can create a new instance. You can then use the Web interface to run SQL statements, import and export data. There is also a Google SQL command line client that can be configured with:

# Java 6 is a dependency of the Google SQL client
$ [ -z `which java 2>/dev/null` ] && sudo apt-get install -y openjdk-6-jre-headless
$ [ -z `which unzip 2>/dev/null` ] && sudo apt-get install -y unzip
$ cd $HOME
$ mkdir cloud-sql
$ cd cloud-sql/
$ wget http://dl.google.com/cloudsql/tools/google_sql_tool.zip
$ unzip ../google_sql_tool.zip
$ ./google_sql.sh 
Please authorize Google SQL Service for your Google Account at:

http://goo.gl/XXXX

Enter Authorization Code: *************************
sql> show schemas;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.10 sec)

NOTE: The *first time* you access your instance you need to confirm authorization by going to the provided URL.