Mysql no database selected error 1046

Mysql no database selected error 1046

Blog Bustle 22/02/2020

We can get mysql no database selected error 1046 when we run any sql query against a specific database and we do not select that database.

When mysql no database selected error 1046 occurs

1. When we use mysql command line

If we use mysql command line we run sql query which is related to any table or view and we did not select database then we get mysql no database selected error 1046 because we create table or view inside database to store our data.

How can we fix this mysql no database selected error 1046?

First i have to select database. After that we run sql query related to this database.

If we want to check database exists or not, how can we check it?

For example, i want to check student database exists or not in mysql server then sql query will be

show databases like 'student';

Select database query syntax

Use database_name;

mysql no database selected

So if we select database before running sql query related to this database we can fix this error.

2. When we use phpMyadmin panel

no database selected error 1046 in phpMyadmin:

A. When we run sql query against a specific database without selecting database.

For example, i want to fetch all data of class table in student database and we did not select student database then we get mysql no database selected error 1046. We can fix this error if we select student database after that we run sql query to fetch all data from class table.

mysql no database selected

B. When we import backup file into specific database without selecting database.

For example, If we want to import student.sql file into student database and we did not select student database then we get mysql no database selected error 1046. So first we have to select student database before importing this sql file to fix this error.

mysql no database selected

So these are types of mysql no database selected error 1046 and their solutions to fix them. Hope you like this tutorial.

Other important links

Rename database in mysql

Copy database in mysql

Import database in mysql

Export database in mysql

Mysql no database selected error 1046 searches:

Tags: #mysql