Skip to content

Instantly share code, notes, and snippets.

@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
@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
@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: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: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: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: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