Bug #55457 MySQL Workbench ignores database specified in connection on import
Submitted: 21 Jul 2010 19:53 Modified: 6 Feb 2013 2:18
Reporter: Matthew Taylor Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Workbench Severity:S3 (Non-critical)
Version:5.2.25 OS:MacOS (10.6.4)
Assigned to: CPU Architecture:Any
Tags: import

[21 Jul 2010 19:53] Matthew Taylor
Description:
MySQL Workbench import fails with Error 1046 No database selected when importing .sql file if .sql file does not include a USE <database> statement.  It will do this when the database to be used is specified as the default schema in the connection parameters.

How to repeat:
1. Connect to a specific MySQL database on the command line.  Dump the database to self contained file or to a project directory.

2. Connect to a specific database using MySQL Workbench.  

3. Confirm that you are working with the desired database.  

4. Attempt an import from the previously exported files into the database you are working with.  The import fails with Error 1046 No database selected results.

Suggested fix:
The database specified as the default schema should be assumed to be the target of any import initiated by Workbench.
[22 Jul 2010 16:51] Johannes Taxacher
Hi Matthew,
at point 3 of your description when you say "import your previously dumped file" do you mean to load it into the query session and run it from the SQL Query editor? or importing again via Administration interface?

The Administration interface does not provide a method to restore a backup into another schema name, and when you create a backup/dump this dump includes a "USE <dumpedschema>" statement which prevents workbench from using the default schema selected in UI.

I guess i'm missing sth in your description, please clarify. thanks in advance.
[22 Jul 2010 18:52] Matthew Taylor
Clarification:

Where I say "import your previously dumped file" I mean import it using the Import from Disk section of the Data Dump tab of the Server Administration interface.

Not all dumps created via command line will include a "USE <dbname>" statement.  Workbench might well do this consistently (I lack the experience with Workbench to know), but I was using Workbench to import a dump file created by another script on another machine as part of a server migration.

I can see this coming up regardless when loading data from one database schema into another, say for testing known good data on a non-production database.

Perhaps then this is not a bug if the behavior is as intended - you can never specify via Workbench what schema you wish to import into - but then I guess for me it is a feature request - I want the ability to use Workbench to move dumps around for testing or migration without hand editing the files to do so, and it will not always be the case that I control where or how the dumps were produced.

Does this clarify sufficiently?

Matthew
[23 Jul 2010 4:16] Valeriy Kravchuk
Based on your last clarification, I'd say this is a reasonable feature request: 

Workbench should allow to import dump to different schema, even if it has to find and change USE statement(s) in the dump accordingly.
[14 Sep 2011 4:31] Stuart Richman
Not all dumps include the USE statement and there doesn't seem to be a way to set the default schema for imports in the Workbench. If the use statement is not included in the dump, then there is no way to import the files.  Each file would need to be manually edit to add the USE statement.
[6 Feb 2013 2:18] Alfredo Kojima
Closing old bug, an option to select the target DB was already added for cases where the imported file does not have it specified.