Published on November 21st, 2020
Have you just begun to learn how to work with SQL files using MySQL?
Maybe you feel a bit lost on how to import files with this tool.
Luckily, importing and exporting files via MySQL is actually quite simple.
Learn how to use MySQL to import SQL files by following the step-by-step guide below.
Looking for simple service to manage your MySQL backups?
→ Try SimpleBackups for free
mysql -u username -p database_name < file.sql
usernamerefers to your MySQL username.
database_namerefers to the database you want to import.
file.sqlis your file name.
mysqlimportcommand and use the following flags and syntax
$ mysqlimport -u magazine_admin -p magazines_production ~/backup/database/magazines.sql
-pare needed for authentication, and is then followed by the name of the database you want to import into.
mysqldumpcommand using the following flags and options:
$ mysqldump -u my_username -p database_name > output_file_path
-uflag specifies the MySQL username.
-pflag specifies a password prompt associated with the above username.
database_nameis the name of the database you want to export.
>symbol is a Unix directive for STDOUT, which will make it possible for Unix commands to output the subsequent results of the output command to another location. These locations are usually file paths.
Making MySQL backups and restoring a MySQL dump (like addressed in this article) is not a complicated task but comes a moment when you'll want to automate it in a way where you can trust your data is secured 100% of the time.
When you have to manage multiple backups, on multiple servers and want a solution you can trust with orchestrating it all in an optimized way, make sure to check out what we do at SimpleBackups.
SimpleBackups automates MySQL backups to securely send backup files offsite to the cloud for storage.