MySql throw no database selected, select the default DB to be used by double-clicking its name

Dung Do Tien Mar 05 2022 29

Hello, I have created a database name is 'chromenotification' in MySql. 

I used MySQL Workbench 8.0 CE to create the database and run the command below to create a table:

CREATE TABLE `notifyhistory` (
   `NotifyHistoryId` int NOT NULL AUTO_INCREMENT,
   `UserId` int DEFAULT NULL,
   `PushDate` datetime DEFAULT NULL,
   `Status` bit(1) DEFAULT NULL,
   `Message` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
   `Title` varchar(100) DEFAULT NULL,
   `Link` varchar(150) DEFAULT NULL,
   PRIMARY KEY (`NotifyHistoryId`),
   UNIQUE KEY `NotifyHistoryId_UNIQUE` (`NotifyHistoryId`)
 ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

But I got an exception No database selected. Select the default DB to be used by double-clicking its name in the SCHEMAS list in the sidebar.

Error Code: 1046. No database selected
Select the default DB to be used by double-clicking its name in the SCHEMAS list in the sidebar.    0.063 sec

How can I select the default database, I find but have not found any dropdown or anything to help set the default database.

Thanks for any help.

Have 2 answer(s) found.
  • S

    Saurabh Shukla Mar 05 2022

    You can run the command USE Your_DB_Name; first. For example:

    USE chromenotification;
    
    CREATE TABLE `notifyhistory1` (
       `NotifyHistoryId` int NOT NULL AUTO_INCREMENT,
       `UserId` int DEFAULT NULL,
       `PushDate` datetime DEFAULT NULL,
       `Status` bit(1) DEFAULT NULL,
       `Message` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
       `Title` varchar(100) DEFAULT NULL,
       `Link` varchar(150) DEFAULT NULL,
       PRIMARY KEY (`NotifyHistoryId`),
       UNIQUE KEY `NotifyHistoryId_UNIQUE` (`NotifyHistoryId`)
     ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci    

    You only need run USE command once time.

  • s

    swarupa Mar 05 2022

    It's so easy, you can add more DB name before the name of the table.

    CREATE TABLE `googlenotification`.`notifyhistory`();

    it will be worked for you.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close