How to import a single table in to mysql database using command line

tismon picture tismon · Mar 22, 2011 · Viewed 313.8k times · Source

I had successfully imported a database using command line, but now my pain area is how to import a single table with its data to the existing database using command line.

Answer

sush picture sush · Mar 22, 2011

Linux :

In command line

 mysql -u username -p  databasename  < path/example.sql

put your table in example.sql

Import / Export for single table:

  1. Export table schema

    mysqldump -u username -p databasename tableName > path/example.sql
    

    This will create a file named example.sql at the path mentioned and write the create table sql command to create table tableName.

  2. Import data into table

    mysql -u username -p databasename < path/example.sql
    

    This command needs an sql file containing data in form of insert statements for table tableName. All the insert statements will be executed and the data will be loaded.