How to import a single table in to mysql database using command line
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.
Solution 1:
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.
Solution 2:
Export:
mysqldump --user=root databasename > whole.database.sql
mysqldump --user=root databasename onlySingleTableName > single.table.sql
Import:
Whole database:
mysql --user=root wholedatabase < whole.database.sql
Single table:
mysql --user=root databasename < single.table.sql