Skip to content

Instantly share code, notes, and snippets.

@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
databaseChangeLog = {
changeSet(author: "adriano (generated)", id: "1473359854018-3") {
sql("""
INSERT INTO bla (field) values (1);
""")
}
}
@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 / 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 / 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 / gist:2208979
Created March 26, 2012 19:31
Configuring mysql with storage engine type InnoDB
/etc/mysql/my.cnf
default-storage-engine=innodb
@adrianosaaquino
adrianosaaquino / gist:2808e2493f478117250e
Created March 12, 2015 14:55
Mysql - Create schema character set and collation
CREATE SCHEMA `name` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
@adrianosaaquino
adrianosaaquino / gist:97c7f505e3ab50235c78
Created March 12, 2015 15:46
MySql - Check foreign key existents
USE information_schema;
SELECT * FROM KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_NAME = 'table_name' AND REFERENCED_COLUMN_NAME = 'table_column' and TABLE_SCHEMA = 'schema_name';
@adrianosaaquino
adrianosaaquino / gist:5372dd87414ff65c07f9
Last active August 29, 2015 14:16
MySql - Create/Restore DUMP from schema structure, no data present
Create dump.
$ mysqldump -uroot -proot --no-data schema_name > file.sql
Restore dump.
$ mysql -uroot -proot schema_name < file.sql