Categories


Browse by


Selected Tag


All Tags 6


RSS Feed

2012

commands line script to extract views or functions or procedures from mysql

  • Mar 16
  • Posted By: Jean-Philippe Blais

This command will extract all views from MySQL (for a given DATABASE_NAME) and create one SQL file per view.

for i in $(echo "select table_name from information_schema.views where table_schema='DATABASE_NAME';" | mysql) ; do echo "select VIEW_DEFINITION from information_schema.views where table_schema='DATABASE_NAME' AND table_name='$i';" | mysql > ${i}.view.sql; done

 

This command will extract all functions from MySQL (for a given DATABASE_NAME) and create one SQL file per function.

for i in $(echo "select ROUTINE_NAME from information_schema.ROUTINES WHERE ROUTINE_SCHEMA='DATABASE_NAME' AND ROUTINE_TYPE='FUNCTION';" | mysql -N); do echo "select ROUTINE_DEFINITION from information_schema.ROUTINES WHERE ROUTINE_SCHEMA='DATABASE_NAME' AND ROUTINE_NAME='$i' AND ROUTINE_TYPE='FUNCTION';" | mysql -N > ${i}.function.sql; done

 

This command will extract all procedures from MySQL (for a given DATABASE_NAME) and create one SQL file per procedure.

for i in $(echo "select ROUTINE_NAME from information_schema.ROUTINES WHERE ROUTINE_SCHEMA='matchmak_bcbpmm' AND ROUTINE_TYPE='PROCEDURE';" | mysql -N); do echo "select ROUTINE_DEFINITION from information_schema.ROUTINES WHERE ROUTINE_SCHEMA='matchmak_bcbpmm' AND ROUTINE_NAME='$i' AND ROUTINE_TYPE='PROCEDURE';" | mysql -N > ${i}.procedure.sql; done

 

If MySQL return file containing \n or \t inside, run this little script to convert them:

for i in *; do sed -i 's/\\n/\n/g' $i; sed -i 's/\\t/\t/g' $i; done

 


Conçu avec Apostrophe CMS
Propulsé par et