Mysql extract datababase a table from a full dump

From Luniwiki
Jump to: navigation, search

Import only one database from a full dump

mysql -p --one-database <database> < <Full_dump>.sql

Example to import database oswh from dump.sql (with other databases)

mysql -p --one-database oswh < dump.sql

Create sql with only a database from full dump of all databases

First we need the header lines of the dump file, and after we print the range of our target database.

sed -n -e '1,/^-- Current Database: `/p' dump.sql | sed '$ d' > dbname.sql
sed -n '/^-- Current Database: `dbname`/,/^-- Current Database: `/p' dump.sql >> dbname.sql

To extract a single table from database dump

 sed -n -e '/DROP TABLE.*`table`/,/UNLOCK TABLES/p' dbname.sql > table.sql

References

Dany (talk) 13:44, 15 November 2017 (EST)