Failed to open file ‘…’ , error 2 and error 22

How to restore a MySQL database in Windows

To restore a MySQL database on a Windows machine:

  • Place the database backup file in the root directory of your C: drive (trust me, this will make your life easier)
  • Open the Command Prompt
  • Start the MySQL command prompt
  • mysql -u root -p

    This command will prompt you for the MySQL root password

  • Switch to the new database
    use db;
  • Import the database
    source C:/BACKUP_FILE_NAME.sql

    To avoid the Failed to open file ‘…’ , error 2 and error 22 error message
    You can have spaces in the name of the backup file, but not in the directory names in the path
    Do not use quotes around the file path
    Use forward slashes
    Do not end the command with semicolon (;)

Leave a comment

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