MySQL Knowledge Base

Exporting/Importing sql Files from Command Line

Exporting

All databases
$ mysqldump -u [uname] -p[pass] --all-databases > all_db_backup.sql
One database
$ mysqldump -u [uname] -p[pass] db_name > db_backup.sql
A specific table from within a database
$ mysqldump -u [uname] -p[pass] db_name table1 table2 > table_backup.sql
Table Structure Only (for a specific table)
$ mysqldump -d -u [uname] -p[pass] db_name table1 > table_backup.sql
$ mysqldump --no-data -u [uname] -p[pass] db_name table1 > table_backup.sql

Importing

Import sql file from the host itself
$ mysql -u username -p -h localhost DATA-BASE-NAME < data.sql
To import to a remote host using IP address
$ mysql -u username -p -h 202.54.1.10 databasename < data.sql
To import to a remote host using hostnames
$ mysql -u username -p -h mysql.cyberciti.biz database-name < data.sql
NULL