Friday, April 27, 2012

MySQL Import Command [ Database Import ]

How do I import data stored in a .sql file (created by mysqldump command) under UNIX or Linux operating systems?

The syntax is as follows to import the data created by mysqldump command:
 
mysql -u {DB-USER-NAME} -p {DB-NAME} < {db.file.sql}
mysql -u {DB-USER-NAME} -h {MySQL-SERVER-HOST-NAME} -p {DB-NAME} < {db.file.sql}
 
In this example import a file called sales.sql for salesdb1 user and sales db, enter:
$ mysql -u sales -p salesdb1 < sales.sql
If database salesdb1 does not exists, first create it and than import it as follows:
$ mysql -u root -p -e 'create database salesdb1'
$ mysql -u sales -p salesdb1 < sales.sql

No comments:

Post a Comment