This is just a quick reminder to those having problems backing up- and importing MySQL databases. Often when I try to import a database using the SOURCE command I will get a SOURCE error 2 message.
The error simply means that we have gotten the file path wrong. However, in my case, it was because I used a less than sign between the SOURCE and the file name. The reason for my mistake is that I use a greater than sign when backing up a database using mysqldump, and sometimes I mess up because the same logic does not apply when importing. Hopefully I will remember it now.
mysql> SOURCE < /home/username/database_backup.sql
Failed to open file '> /home/username/database_backup.sql', error: 2
If you have made the same mistake, simply remove the greater than sign from your statement, and it should look like this:
The problem can also be that you miss typed the path for the .sql file, though I suppose this is unlikely if you know what you are doing, but be sure to double check this as well.
Alternatively, you can also import databases using mysql in a terminal, in which case you will be using the greater than sign:
mysql database_name < database_name.sql
To create a .sql backup of a database, use mysqldump:
mysqldump database_name > database_name.sql