Edit Article

Edited by Candyy., Choicefresh, Nicole Willson, Brandywine and 2 others

Multiple backups should be taken. E.g.

  • One copy on the same computer or locally networked computer that can be used to quickly replace a database that is in use.
  • Another copy in a physically different location in case something happens at the current location (fire, flood). This could be another computer at a remote site or some portable medium like a tape or CD.

If using Windows, open a command prompt window. If using Linux, execute the commands on the command line. The examples below are for Linux - convert backslashes and add .exe to the command for the Windows equivalents.

EditSteps

  1. Backup and Restore Data in MySQL Step 1.jpg
    1
    To make a backup:
    • mysqldump --user=username --password=password databasename >path/backupfilename
  2. 2
    To repair a table:
    1. Stop the MySQL server:
      Backup and Restore Data in MySQL Step 2Bullet1.jpg
      • mysqladmin -u username -p 'password' shutdown
    2. Start the repair:
      • myisamchk -r databasepath/databasename/tablename.MYI
        • databasepath - The complete path to your data directory.
        • tablename can be "*" which means fix all tables.
    3. You should see output on the screen telling you which tables are being checked.
      Backup and Restore Data in MySQL Step 2Bullet3.jpg
    4. Restart the MySQL server:
      • mysqladmin -u username -p start
  3. 3
    If the repair doesn't work, you may need to delete the table and restore from the backup file:
    1. Delete the table - in MySQL, send the query:
      Backup and Restore Data in MySQL Step 3Bullet1.jpg
      • DROP TABLE tablename
    2. Back at the command prompt:
      Backup and Restore Data in MySQL Step 3Bullet2.jpg
      • mysql -u username -p databasename < /path/backupfilename


Add your own method
Save

EditVideo



EditWarnings

  • The backup file contains all INSERT commands to restore all tables you specified when you made the backup. If you only want to restore some of the tables, you'll need to edit the backup file before running the restore command.

Article Info

Categories: MySQL

Recent edits by: Maluniu, Brandywine, Nicole Willson

Thanks to all authors for creating a page that has been read 11,558 times.

Was this article accurate?

YesNo