MySQL backup & Restore

Backup database or table

  • mysqldump -p database table_name > /tmp/table.sql
  • mysqldump -p database > /tmp/database.sql

Only schema

  • mysqldump  -p database  –compact –no-data > /tmp/database.sql

Restore database

  • mysql -p database < dumpfilename.sql

Remember create database first

Restore table from database dump

  • cat mydumpfile.sql | sed -n -e ’/CREATE TABLE.*`table_name`/,/CREATE TABLE/p’ database.sql > table.sql