Bug #96487 error code 1046 (42000) no database selected
Submitted: 9 Aug 2019 13:41 Modified: 15 Aug 2019 12:52
Reporter: Daniel Lewis Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Workbench: SQL Editor Severity:S3 (Non-critical)
Version:8.0.17, 8.0.21 OS:Ubuntu (18.04)
Assigned to: CPU Architecture:Other (x86_64 AMD)

[9 Aug 2019 13:41] Daniel Lewis
Description:
   I created a new database `test` in workbench with one table `first` with 2 rows of data. Then Server > Data Export. I checked the database `test` which also checked the table `first`. Export to self-contained file: enter the name of the file and its location. Clicked Start Export.
   Importing this file: Server > Data Import; selected Import from self-contained file; browsed to the location of the file I had exported. Start Import: almost immediately I got the error 1046 (42000) ... no database selected.
   I believe that the export function is not including all of the information needed for a later import. Two examples follow with the first one having the first several lines of the created .sql file (Distrib 8.0.17), and the second one having the same lines for another export file (Distrib 5.5.47). I have used this file to import data with no complaint at all. I might also add that I can export the database `test` using Export Dump Project Folder and then Import from that folder.
   Example #1: -- MySQL dump 10.13  Distrib 8.0.17, for Linux (x86_64)
--
-- Host: localhost    Database: test
-- ------------------------------------------------------
-- Server version	8.0.17

   Example #2: CREATE DATABASE  IF NOT EXISTS `Bible` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `Bible`;
-- MySQL dump 10.13  Distrib 5.5.47, for debian-linux-gnu (x86_64)
--
-- Host: 127.0.0.1    Database: Bible
-- ------------------------------------------------------
-- Server version	5.5.47-0ubuntu0.14.04.1

How to repeat:
1) open workbench and connect to the server.
2) Create a new schema.
3) Create a new table with three fields in this schema.
4) Populate the table with two rows of data.
5) Server > Data Export
6) Select the database.
7) Select Export to self-contained file.
8) Browse to where the file should be located and give it a name.
9) Click Start Export.
10) Server > Data Import
11) Select Import from self-contained file
12) Browse to the file's location
13) Click Start Import
[9 Aug 2019 16:55] MySQL Verification Team
Thank you for the bug report. Please try a server version 5.6 or higher, 5.5.XX isn't more supported: https://dev.mysql.com/doc/workbench/en/wb-requirements.html.
[9 Aug 2019 18:17] Daniel Lewis
On March 3, 2018, I created the file mysql_2018-03-03_0668.sql using workbench 5.5.47. Example #2 contains the top several rows of that file. While 5.5.47 may not be supported, I did use workbench 8.0.17 to import the data and structure from this file. This was for comparison only. I see that the export file created by workbench 5.5.47 begins with a Create Database statement. Export files created by workbench 8.0.17 does not begin with this statement. To me, this explains why the error code 1046 stating "no database selected". Question how to modify the export file so that it contains a Create Database statement that workbench will accept.
[12 Aug 2019 23:45] MySQL Verification Team
Create schema option to export data

Attachment: 96487.png (image/png, text), 102.61 KiB.

[12 Aug 2019 23:46] MySQL Verification Team
See screen-shot with option to create schema when export data.
[13 Aug 2019 0:09] MySQL Verification Team
Include Create Schema for export data

Attachment: export_data_on_ubuntu.png (image/png, text), 83.63 KiB.

[15 Aug 2019 12:52] Daniel Lewis
I have first managed to bring all my database data up to date. Then I exported it making sure I checked the box Include Create Schema. Finally, I imported what I had just exported. There were no problems for this. So, you have solved my problem just as you expected. Thanks!!!!
[22 Sep 2020 12:18] MySQL Verification Team
Bug #100873 marked as duplicate of this one.