Skip to content

Instantly share code, notes, and snippets.

databaseChangeLog = {
changeSet(author: "adriano (generated)", id: "1473359854018-3") {
sql("""
INSERT INTO bla (field) values (1);
""")
}
}
@adrianosaaquino
adrianosaaquino / biggerTable.sql
Created April 29, 2016 21:40
Mysql: maiores tabelas
SELECT CONCAT(table_schema, '.', table_name),
CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows,
CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') DATA,
CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') idx,
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size,
ROUND(index_length / data_length, 2) idxfrac
FROM information_schema.TABLES
ORDER BY data_length + index_length DESC
LIMIT 20;
@adrianosaaquino
adrianosaaquino / setTimeZone.groovy
Last active April 29, 2016 21:38
Set TimeZone in Grails Application
// In BootStrap.conf
// TimeZone.availableIDs -> ['Etc/GMT+12', 'Etc/GMT+11', 'Pacific/Midway', 'Pacific/Niue'.....
TimeZone.setDefault(TimeZone.getTimeZone("America/Sao_Paulo"))
@adrianosaaquino
adrianosaaquino / mysqlCreateDump.sh
Last active April 29, 2016 21:46
MySql - Create/Restore DUMP from schema structure and data compressed with progress, no lock tables
/*Required install PV (Pipe Viewer)
Create dump.*/
$ mysqldump --single-transaction --skip-add-locks --skip-comments -uroot -proot schema | pv | gzip -c > file.sql.gz
/*Restore dump.*/
$ pv file.sql.gz | gunzip | mysql -uroot -proot schema
@adrianosaaquino
adrianosaaquino / gist:1f1225c399577b46153f
Last active April 29, 2016 21:52
MySql - Create/Restore DUMP from schema structure and data compressed with where, one table
Create dump.
$ mysqldump -uroot -proot schema_name table_name -w "date between '2013-01-01 00:00:00' and now()" | \
gzip > schema_name_table_name.sql.gz
Restore dump.
$ gunzip schema_name_table_name.sql.gz | mysql -uroot -proot schema_name
@adrianosaaquino
adrianosaaquino / gist:b1ca9d06a1399147e2fd
Created March 12, 2015 17:08
MySql - Create/Restore DUMP from all schemas, structure and data compressed
Create dump.
$ mysqldump -uroot -proot --all-databases | gzip > file.sql.gz
Restore dump.
$ gunzip file.sql.gz | mysqldump -uroot -proot
@adrianosaaquino
adrianosaaquino / gist:734f40169542400d7436
Created March 12, 2015 17:03
MySql - Create/Restore DUMP from schema structure and data compressed, one table only
Create dump.
$ mysqldump -uroot -proot -B schema --table table_name | gzip > file_schema_table.sql.gz
Restore dump
$ gunzip file_schema_table.sql.gz | mysqldump -uroot -proot schema
@adrianosaaquino
adrianosaaquino / gist:1f812a4f183d72613824
Last active August 29, 2015 14:16
MySql - Create/Restore DUMP from schema structure and data compressed, no lock tables
Create dump.
$ mysqldump --single-transaction --skip-add-locks --skip-comments -uroot -proot schema | gzip -c > file.sql.gz
Restore dump.
$ gunzip < file.sql.gz | mysql -uroot -proot schema
@adrianosaaquino
adrianosaaquino / gist:205dfda6d9d70bff9302
Last active August 29, 2015 14:16
MySql - Create/Restore DUMP from schema structure and data compressed
Create dump.
$ mysqldump -uroot -proot schema | gzip -c > file.sql.gz
Restore dump.
$ gunzip < file.sql.gz | mysqldump -uroot -proot schema
@adrianosaaquino
adrianosaaquino / gist:12b7dd95aff77434b8fc
Created March 12, 2015 15:54
MySql - Create/Restore DUMP with structure and data
Create dump.
$ mysqldump -uroot -proot schema_name > file.sql
Restore dump.
$ mysql -uroot -proot schema_name < file.sql