2018-09-08

Crear y restaurar Backups en bases de datos mysql

Crear copia de seguridad de base de datos my sql

mysqldump -u [user] -p[pass] [database_name] > [filename].sql
mysqldump -u [user] -p[pass] -h [IP] [database_name] > [filename].sql 
mysqldump -u [user] -p[pass] [database_name] | gzip > [file_name].sql.gz
mysqldump -u [user] -p[pass] –databases [database_name_1] [database_name_2] [database_name_n] > [filename].sql
mysqldump -u [user] -p[pass] [database_name] | bzip2 > [file_name].sql.bz2
mysqldump -u [user] -p[pass] –all-databases > [file_name].sql
mysqldump -u [user] -p[pass] [database_name] > [filename].sql

Crear Base de datos, crear usuario y restaurar backup

mysql -u [user] -p
create database [database_name];
grant all privileges on [database_name].* to [new_user]@[hostname] identified by [new_user_password];
exit;

Restaurar BackUP

mysql -u [new_user] -p[new_user_password] [database_name] < [file_name].sql

Si está comprimido

gunzip [file_name].sql.gz
bunzip2 [file_name].sql.bz2