Home » Restore MySQL backup from the terminal

Efficiently import MySql backup database records from an .sql file using the mysql command from the terminal. A quick and direct approach to restore MySQL backup files from the terminal.

For example.

mysql -uNAME -p DATABASE < database_backup.sql

Enter the PASSWORD when prompted.

Enter password:

Where.

  • NAME is the user who has access to the database.
  • PASSWORD is the password of the user.
  • DATABASE is the name of the database where the backup file will be imported.
  • database_backup.sql is the backup sql file to be restored.

Notes:

  • Because the path where the .sql file to be restored was not specified, mysql will assume that the .sql file (database_backup.sql) is on the same location where the command is executed.
  • The same command can also be executed on windows command line.

Other Examples

Specifically import from linux home directory.

mysql -uNAME -p DATABASE < /home/database_backup.sql

Specifically import from windows drive D.

mysql -uNAME -p DATABASE < D:\database_backup.sql

References:


Posted

in

by

Leave a Reply

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