How to back up tables in a MySQL database

There are two methods available for backing up tables in a MySQL database:

  1. Backup using the mysqldump command:
  2. Open the command line or terminal window, and navigate to the ‘bin’ folder within the MySQL installation directory.
  3. Use the following command to backup a single table: mysqldump -u username -p database_name table_name > backup.sql

    Here, username refers to the username of the database, database_name is the name of the database to be backed up, table_name is the name of the table to be backed up, and backup.sql is the path and filename for the backup file.

  4. After pressing the enter key, the system will prompt for the database password. Once the password is entered, the backup command will be executed and generate an SQL file.
  5. To backup multiple tables, you can specify multiple table names in the command, separated by space: mysqldump -u username -p database_name table_name1 table_name2 > backup.sql
  6. Back up with MySQL Workbench:
  7. Open MySQL Workbench and connect to the database server that you want to backup.
  8. Select “Server” on the navigation bar, then choose “Data Export”.
  9. Choose the tables to backup in the “Tables to Export” section.
  10. In the “Export to Dump Project Folder” section, select the folder where you want to save the backup files.
  11. When you click on the “Start Export” button, MySQL Workbench will create an SQL file that contains backup data for the selected table.

Tables can be restored by importing backup files into another MySQL database, using any method.

bannerAds