Bobcares

SQL Error 1046 – Resolve it now

by | Jul 23, 2020

SQL error 1046 occurs if the database is not selected.

Here at Bobcares, we have seen several such SQL related issues as part of our Server Management Services for web hosts and online service providers.

Today we’ll take a look at the cause for this error and how to fix it.

 

What causes SQL error 1046 to occur

Generally, this error occurs when creating tables or while recovering the tables from any backup.

For example, let’s say that we have created a database and provided a password as well.
Now while creating the table if we forget to mention the database name then we will end up with this error message.

This happens because SQL is not aware of which database we are going to use.

Also, the same goes while importing tables from any backup.

For instance, the error appears as below.

SQL Error 1046

 

How we fix SQL error 1046

Now let’s look into different solutions provided by our Support Engineers.

1. Recently, one of our customers approached us with the same error message while creating a table.

We then replicated the error and could find that the customer wasn’t selecting the database to create a table.

So we suggested running the below command so that the database gets selected.

USE database_name;

In case, if the database doesn’t exist then we ask customers to create it via below command

CREATE DATABASE database_name;

After this step, we suggested the customer create the tables. Finally, he was able to create it with no more errors.

 

2. Alternately, we also provide the below command to select the database.

mysql -u example_user -p –database=work < ./work.sql

 

3. In some situations, if the customer has the database file then we import the database in phpMyAdmin for them. Here are the steps that we follow to do so.

  • First, we access the phpMyAdmin. Then select the database created by the customer from the list of databases on the left of the page.
  • Here, we click on the Import option available on the top bar.
  • Then click on the ‘Browse‘ button available next to the ‘Location of the SQL file‘.
  • Here, we browse the local SQL file and open it. After that, we choose the format as ‘SQL‘.
  • Finally, we click on the ‘Go‘ button and wait for the database to get imported.

NOTE: We follow the above steps to import the database only after creating it.

[Need any further assistance in fixing SQL errors? – We’re available 24*7]

 

Conclusion

In short, this error can arise if we forget to select the database before creating tables or importing .sql file. Today, we saw the resolution to this SQL error.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.