SQL is a popular language used for managing servers and databases. If using an SQL database, you may come across this error called ‘No Database Selected’.
As evident from the message, the problem occurs because there is no database selected prior to importing the SQL file. Fortunately, its not a severe error. You can fix it in more than one ways. Below are five solutions to this the No Database Selected problem in SQL File Import.
Method 1
The first method involves the following steps:
Execute this command to name the database before creating the table:
If the table doesn’t exist yet, exeucte the following command to create a new one and then the previous command to name the database:
Method 2
In the second method, you simply can select the database by executing the below command:
Method 3
For MySQL Workbench users, here are the steps you need to follow:
From the left hand side pane of welcome window, locate and click on Object Browser
From the drop-down menu, select the required database
Next, from Workbench splash screen, navigate to SQL Development and click on Manage Connections
Method 4
If you’re having the SQL database file, then you have the option of importing it into PhpMyAdmin to fix the error. Here are the steps involved
Method 5
The last method is to import a database after creating it. Here are the steps involved in this process:
So these were some of the ways to fix the ‘No Database Selected’ error during SQL file import. Select the option that best suits your needs.
As evident from the message, the problem occurs because there is no database selected prior to importing the SQL file. Fortunately, its not a severe error. You can fix it in more than one ways. Below are five solutions to this the No Database Selected problem in SQL File Import.
Method 1
The first method involves the following steps:
Execute this command to name the database before creating the table:
Code:
USE database_name;
Code:
CREATE DATABASE database_name;
In the second method, you simply can select the database by executing the below command:
Code:
mysql -u example_user -p --database=work < ./work.sql
For MySQL Workbench users, here are the steps you need to follow:
From the left hand side pane of welcome window, locate and click on Object Browser
From the drop-down menu, select the required database
Next, from Workbench splash screen, navigate to SQL Development and click on Manage Connections
Method 4
If you’re having the SQL database file, then you have the option of importing it into PhpMyAdmin to fix the error. Here are the steps involved
- Make sure you have a new MySQL database on your Live Site
- On the live site, navigate to phpMyAdmin and log in to your database
- From the list of databases, select the required database
- From the top bar, click on Import
- Next, click on Browse option
- Select the SQL file on your local machine and click on Open. In case its zipped, you have to unzip it first.
- Next, you have to select the format as SQL and then click on Go
- It will take some time for the file to be uploaded
Method 5
The last method is to import a database after creating it. Here are the steps involved in this process:
- Using phpMyAdmin and create a new database
- Start using the database by executing the following command:
Code:
use database_name