Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating DDL statements of database from Google Cloud Sql using eclipse cause issue in script?

Tags:

I connected to a Google Cloud SQL database from eclipse using Data Source explorer. But when I generate DDL of that database using its option Generate DDL, I can't get the AUTO_INCREMENT in my script but get the corresponding primary key.

How would i go about getting the AUTO_INCREMENT in my script?

like image 623
Master Mind Avatar asked Jun 21 '12 12:06

Master Mind


People also ask

How do I connect Google Cloud database to SQL?

In the Google Cloud console, go to the Cloud SQL Instances page. To open the Overview page of an instance, click the instance name. Select Connections from the SQL navigation menu. In the Authorized networks section, click Add network and enter the IP address of the machine where the client is installed.

Which database engines does Cloud SQL support?

Cloud SQL is a fully-managed database service that helps you set up, maintain, manage, and administer your relational databases on Google Cloud Platform. You can use Cloud SQL with MySQL, PostgreSQL, or SQL Server.

Is Google Cloud SQL a database?

Google Cloud SQL is a managed database service that allows you to run Microsoft SQL Server, MySQL, and PostgreSQL on Google Cloud. The service provides replication, automated backups, and failover to ensure high-availability and resilience.


1 Answers

While this is not directly answering the question, I believe it will provide a solution to the root goal: Extracting the DDL.

Assumption: The following is a shell script, so an appropriate environment (OS X, Linux, cygwin) is required

Steps:

  1. Install the command line scripts (follow the instructions here)
  2. Create the following custom script in the same directory as the google_sql.sh:

    GOOGLE_CLOUD_SQL_INSTANCE=test:test  echo "SELECT CONCAT('SELECT CONCAT(\"SHOW CREATE TABLE ',schema_name,'.\",table_name,\";\") \"select \\\\\"use ',schema_name,';\\\\\";\" FROM information_schema.tables WHERE table_schema = \"',schema_name,'\";') 'use information_schema;' FROM SCHEMATA WHERE schema_name NOT IN ('information_schema','mysql','performance_schema');" >> $$.1.get_schema.sql  ./google_sql.sh $GOOGLE_CLOUD_SQL_INSTANCE information_schema < $$.1.get_schema.sql > $$.2.show_create.sql  ./google_sql.sh $GOOGLE_CLOUD_SQL_INSTANCE information_schema < $$.2.show_create.sql > $$.3.sql.out  ./google_sql.sh $GOOGLE_CLOUD_SQL_INSTANCE information_schema < $$.3.sql.out > $$.4.create.raw  awk -F"  " '/Table Create Table/{print "";}  /CREATE/{sub(/^..*CREATE TABLE/,"CREATE TABLE");print $0}  $1 == "" {print $0}  /^\)/{print $0";"}  /^use/{print $0}' $$.4.create.raw > $GOOGLE_CLOUD_SQL_INSTANCE.ddl.sql  rm $$.* 
  3. Replace "test:test" in the script with your Google Cloud instance identifier

  4. Execute the script to produce a file of the format "test:test".ddl.sql which will have the DDL for all tables in all databases.
like image 163
Drew Avatar answered Oct 04 '22 08:10

Drew