HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How to import only a specific database from a .sql file?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
filehowsqldatabasespecificfromonlyimport

Problem

I have a file dump.sql with many databases in it: mydb1, mydb2, mydb3, etc.

How to import only mydb3 and not the other databases?

Won't:

mysql> create database mydb3;
mysql> use mydb3;
mysql> source /path/to/dump.sql;


import all databases?

Solution

You can use the --one-database option or -o for short:

mysql ... -o mysb3 < /path/to/dump.sql


Note that the documentation page in the link above states:

This option is rudimentary and should be used with care.

However, I think dump files created by mysqldump should be safe enough.

Note: this doesn't run the actual CREATE DATABASE ... statement, so you have to do that before you import.

Code Snippets

mysql ... -o mysb3 < /path/to/dump.sql

Context

StackExchange Database Administrators Q#303511, answer score: 5

Revisions (0)

No revisions yet.