Bug #42996 --one-database does not only import the specified database
Submitted: 18 Feb 2009 22:32 Modified: 13 Aug 2009 1:17
Reporter: Donna Harmon Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.0.68,5.1.28.5.1.30 OS:Any
Assigned to: Assigned Account CPU Architecture:Any

[18 Feb 2009 22:32] Donna Harmon
Description:
the mysql option --one-database does not only import the specified database and gives a "ERROR 1049 (42000): Unknown database 'database2'" error for database that I am trying to import even though a "CREATE DATABASE IF NOT EXISTS" statement is in the backup but it does not give that same error for other databases that do not exist that it creates.

How to repeat:
Create a full backup with mysqldump:
shell> mysqldump -uroot -p --all-databases > fulldump.db

Drop two databases, one being the one to import
mysql> drop database1
mysql> drop database2

Attempt to Import only database2
shell> mysql -uroot -p --one-database database2 < fulldump.db

mysql> show databases;
...
database1          | 
database2    
...

Suggested fix:

WORKAROUND:

Use New User Account method shown in https://kb.mysql.com/view.php?id=8316 which is as follows:

mysql> GRANT SELECT ON *.* TO 'restorative_user'@'localhost' identified by 'password';

FOR IMPORTING A SPECIFIC TABLE ONLY:
mysql> GRANT ALL ON database2.table1 TO 'restorative_user'@'localhost';

FOR IMPORTING A SPECIFIC DATABASE ONLY:
mysql> GRANT ALL ON database2.* TO 'restorative_user'@'localhost';

Restore the backup using the new user account.
shell> mysql -u restorative_user -ppassword --force < /path/fulldump.db
[16 Apr 2009 12:40] MySQL Verification Team
http://bugs.mysql.com/bug.php?id=40477
[13 Aug 2009 1:17] Donna Harmon
Appears to be a duplicate of http://bugs.mysql.com/bug.php?id=40477