MySQL Import File / Database Command

The mysqldump command line client is a backup program and it can be used to dump a database (backup database) or a collection of databases for backup or transfer to another SQL server. The dump typically contains SQL statements to create the table, populate it, or both. A common use of mysqldump is for making a backup of an entire database:

 
mysqldump db_name > backup-db_name.sql
mysqldump -u userNameHere db_name > backup-db_name.sql
mysqldump -u userNameHere -p db_name > backup-db_name.sql
 

You can import such a file using mysql command.

Syntax

The syntax is as follows to import the data created by mysqldump command:

 
mysql -u {DB-USER-NAME} -p {DB-NAME} < {db.file-name.sql}
mysql -u {DB-USER-NAME} -h {MySQL-SERVER-HOST-NAME} -p {DB-NAME} < {backup.db.file-name.sql}
mysql -e "source /path/to/backup-db.sql" db_name_here
mysql -u DB_USER_NAME -p -e "source /path/to/backup-db.sql" db_name_here
 

 

Revisions

No comments yet.

Leave a Reply