How to import a single table in to mysql database using command line
Linux :
In command line
mysql -u username -p databasename < path/example.sql
put your table in example.sql
Import / Export for single table:
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 thecreate table
sql command to create tabletableName
.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 tabletableName
. All theinsert
statements will be executed and the data will be loaded.
All of these options are fine, if you have the option to re-export the data.
But if you need to use an existing SQL file, and use a specific table from it, then this perl script in the TimeSheet blog, with enable you to extract the table to a separate SQL file, and then import it.
The original link is dead, so it is a good thing that someone has put it instead of the author, Jared Cheney, on GitHub, in this link.