backup mysql databases

steps to perform mysql databases backup:
  • put the server  in a read-only state:
    FLUSH TABLES WITH READ LOCK;
    SET GLOBAL read_only = ON;
  • backup data via this script or:
    mysqldump -h host_name --user=user_name --password=password --events --opt --single-transaction db_for_backup | gzip > backup_name.gz
  • turn off read-only mode:
    SET GLOBAL read_only = OFF;
    UNLOCK TABLES;
to restore db from backup:
  • you can use this script
  • or:  mysql -u user "db_name" < backup_name
  • or: gunzip < backup_name.gz | mysql -u user -p password db_name
No comment yet
Leave a Reply

Your email address will not be published. Required fields are marked *