Sql error 1046 3d000 no database selected dbeaver

Start DBeaver Open new SQL editor run a query like "SELECT * FROM " Error: No database selected even though at the dropdown at the top there's a database selected (...

This happens to me without DBeaver even having to close… when just unlocking my Mac in the morning, after having used several query tabs started from an already-connected database schema. I’m using version 22.3.0.202212041619.

Here’s what I did to have it happen:

  1. Right-click the database schema (MySQL), select SQL Editor > New SQL Script.
  2. Make any SELECT query, run it and see results.
  3. Lock the Mac then go to bed.
  4. Unlock the Mac in the morning, try running the query again, and get the error.

Here’s what didn’t fix it:

  1. Executing the query using Ctrl+Enter or any other execution method (like one of the buttons).
  2. Right-clicking the schema or database and selecting Refresh, then trying to execute again.
  3. Right-clicking from within the query tab, selecting Execute, then either ‘Set active connection’ or ‘Select active schema’, choosing the same database name or schema name that’s already in the tab’s name, then trying to execute again.

Here’s what did fix it:

  1. Closing DBeaver, saving tab unsaved tabs when prompted, opening DBeaver again, then executing the query.

I don’t know how to explain this, but the query tabs just become irretrievably disconnected after a while, and I’m not sure what causes this. Maybe the Mac went to sleep, and DBeaver can’t handle that? I figured if the query tab’s name already contains the names of the database and schema that it would understand those are what the query tab is for, but it forgets for some reason, and sometimes just cannot connect again no matter what I do unless I just restart the app.

Any explanation for this? I think this is far beyond an improper naming situation… the tab names should stay the same, never switch to ‘none’ or whatever, and should retain/refresh the association/connection of the tab to its database and schema, even if that requires a manual re-connect (though I don’t see why it should, it should reconnect when I try to run the query again). I haven’t had this sort of issue with MySQL Workbench in the many years I’ve used it, I just haven’t used it recently because of some unrelated crashes. DBeaver can do better.

The error no database selected frequently occurs in MySQL when you perform a statement without selecting a database first.

In the following example, I tried to query a students table immediately after connecting to the mysql command line:

mysql> SELECT * FROM students;

ERROR 1046 (3D000): No database selected

To resolve this error, you need to first select a database to use in the command line by running the USE command:

You need to replace [database_name] with the name of a database that exists in your MySQL server.

You can also list the names of all databases available on your server with the SHOW DATABASES command.

The following shows the output on my computer:

mysql> SHOW DATABASES;

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| school_db          |
| sys                |
| test_db            |
+--------------------+

Next, issue the USE command as shown below:

mysql> USE school_db;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> 

The error should be resolved once mysql responds with Database changed as shown above.

The same applies when you’re using a graphical user interface for managing MySQL databases like MySQL Workbench or Sequel Ace.

Just run the USE command before running any other statements:

USE school_db;
SELECT * FROM students;
SELECT * FROM cities;

The error can also happen when you run a .sql script file from the command line without adding a USE command:

mysql -uroot -p < ./files/query.sql
Enter password: 

ERROR 1046 (3D000) at line 1: No database selected

To run the .sql file, you need to add a USE statement inside the SQL file itself.

Alternatively, you can also select the database you want to use from the command line as follows:

mysql -uroot -p school_db < ./files/query.sql   
Enter password: 

id	name
3	Bristol
4	Liverpool
1	London
2	York

You need to add your database name after the -p option and before the < symbol.

And that’s how you can resolve the error no database selected in MySQL database server 😉

This article is a step-by-step guide to resolve the “MySQL ERROR 1046 (3D000) No Database Selected” error. If you are a DBA or a developer, this post will help you fix this MySQL 1046 error.

If you are getting this error message means you are trying to execute MySQL queries statement using the MySQL command prompt. Let’s go through why we get the error 1046 (3D000) followed by the step-by-step procedure to resolve this error.

Why you are getting MySQL Error 1046 (3D000) No database selected?

MySQL ERROR 1046 (3D000) No Database Selected

Let me tell you first why you are getting this 1046 MySQL error message.  You might have guessed it right by now; the error message is pretty clear that you have not selected the database before executing your MySQL statement.

This error generally occurs when you try to create a Table in the MySQL database using the command prompt.

Because while executing a command from the command prompt you need to select the database also since MySQL will not be able to know for which database you are executing the script.

When you execute create table statement from MySQL workbench then at that time you need to manually select the database then you execute your statement. Similarly, while executing a script from the command prompt screen, make sure you have provided the database name.

The next question is “how to provide the database name?” No worries. Here are the steps; just follow the below steps by step procedure to get rid of the error.

Steps to resolve MySQL ERROR 1046 (3D000) No Database Selected:

Step 1:

  • Open MySQL command prompt.
  • Go to the start menu and open MySQL Command Line Client.

MySQL command line client

Step 2: Select the database

If you know the database name:

  • Select the Database on which you want to execute your script.
  • If you know the name of the database, then enter the database name in the following format.

use <database_name>;

select and use a database in MySQL

Note: Don’t skip this step, this is the solution to get rid of the 1046 (3D000) error message.

If you do not know the database name:

If you don’t know the available database names or the database on which you are going to execute the script, then you can list all available databases using the following command.

SHOW databases;

Show database command lists down all the databases available. Then you run use <database_name>;

Show database in MySQL

Step 3: Execute statement

Once the database is selected, you can execute your required SQL statement. Here we will execute create table statement in the database as an example.

mysql create table no database selected fix - table created

That’s it. You can see the created table in the MySQL database using MySQL workbench.

Table created in MySQL

Conclusion:

Is it not simple? I hope you now know the reason behind the “MySQL error 1046 No Database selected error” issue and how to fix it. Do share your feedback if this post helped you to fix the MySQL 1046 (3D000) error using the above steps in the comment section.

Cheers !!!

Similar article:
1. Fix “unknown collation ‘utf8mb4_unicode_520_ci’” Error

Страницы 1

Чтобы отправить ответ, вы должны войти или зарегистрироваться

1 2009-01-24 22:44:24

  • BadMoroz
  • Редкий гость
  • Неактивен
  • Зарегистрирован: 2009-01-24
  • Сообщений: 3

Тема: ошибка #1046 — No database selected

Привет всем!! У меня такая проблема( При импорте БД пишет такую ошбку #1046 — No database selected

Ошибка

SQL-запрос:

CREATE TABLE `jos_banner` (
`bid` int( 11 ) NOT NULL AUTO_INCREMENT ,
`cid` int( 11 ) NOT NULL default ‘0’,
`type` varchar( 30 ) NOT NULL default ‘banner’,
`name` varchar( 255 ) NOT NULL default »,
`alias` varchar( 255 ) NOT NULL default »,
`imptotal` int( 11 ) NOT NULL default ‘0’,
`impmade` int( 11 ) NOT NULL default ‘0’,
`clicks` int( 11 ) NOT NULL default ‘0’,
`imageurl` varchar( 100 ) NOT NULL default »,
`clickurl` varchar( 200 ) NOT NULL default »,
`date` datetime default NULL ,
`showBanner` tinyint( 1 ) NOT NULL default ‘0’,
X`checked_out` tinyint( 1 ) NOT NULL default ‘0’,
`checked_out_time` datetime NOT NULL default ‘0000-00-00 00:00:00’,
`editor` varchar( 50 ) default NULL ,
`custombannercode` text,
`catid` int( 10 ) unsigned NOT NULL default ‘0’,
`description` text NOT NULL ,
`sticky` tinyint( 1 ) unsigned NOT NULL default ‘0’,
`ordering` int( 11 ) NOT NULL default ‘0’,
`publish_up` datetime NOT NULL default ‘0000-00-00 00:00:00’,
`publish_down` datetime NOT NULL default ‘0000-00-00 00:00:00’,
`tags` text NOT NULL ,
`params` text NOT NULL ,
PRIMARY KEY ( `bid` ) ,
KEY `viewbanner` ( `showBanner` ) ,
KEY `idx_banner_catid` ( `catid` )
) ENGINE = MYISAM DEFAULT CHARSET = utf8 AUTO_INCREMENT =1

2 Ответ от Hanut 2009-01-25 01:53:52

  • Hanut
  • Hanut
  • Модератор
  • Неактивен
  • Откуда: Рига, Латвия
  • Зарегистрирован: 2006-07-02
  • Сообщений: 9,723

Re: ошибка #1046 — No database selected

BadMoroz
Сперва выберите (создайте, если надо) БД, в которую вы осуществляете импорт.

3 Ответ от BadMoroz 2009-01-25 15:06:44

  • BadMoroz
  • Редкий гость
  • Неактивен
  • Зарегистрирован: 2009-01-24
  • Сообщений: 3

Re: ошибка #1046 — No database selected

Hanut сказал:

BadMoroz
Сперва выберите (создайте, если надо) БД, в которую вы осуществляете импорт.

БД создана и выбрана. всёравно выкидывае ошибку((( #1046

4 Ответ от BadMoroz 2009-01-25 15:14:21

  • BadMoroz
  • Редкий гость
  • Неактивен
  • Зарегистрирован: 2009-01-24
  • Сообщений: 3

Re: ошибка #1046 — No database selected

Hanut сказал:

BadMoroz
Сперва выберите (создайте, если надо) БД, в которую вы осуществляете импорт.

Простите за невнимательность все загрузил! Большое спасибо

5 Ответ от Игорь Карасёв 2009-11-20 18:30:06

  • Игорь Карасёв
  • Редкий гость
  • Неактивен
  • Зарегистрирован: 2009-11-20
  • Сообщений: 6

Re: ошибка #1046 — No database selected

BadMoroz Расскажи как справился с проблемой?

6 Ответ от pritvorshik 2013-01-30 12:03:51

  • pritvorshik
  • Новичок
  • Неактивен
  • Зарегистрирован: 2013-01-30
  • Сообщений: 1

Re: ошибка #1046 — No database selected

Нужно слева в списке выбрать базу данных нажав на нее если она уже создана и лишь после импортировать файл имябазы.sql
Либо если там ее нет то создать, выбрать нажав на нее и лишь после импортировать файл с базой данных.
Так же если на хостинге разрешена лишь одна база данных с большим количеством мб, а сайтов можно создать более одного, два,  три и больше то ты просто меняешь либо добавляешь другой префикс к примеру на первый сайт префикс  ya_  на второй ti_  и в той же базе можешь повесить не один сайт c одной базой данных, с учетом если позволяет размер выделенный на базу хостером.

Страницы 1

Чтобы отправить ответ, вы должны войти или зарегистрироваться

Понравилась статья? Поделить с друзьями:
  • Sql error 0a000 ошибка ссылки между базами не реализованы
  • Sql error 0a000 error cross database references are not implemented
  • Sql error 08s01 java lang nullpointerexception
  • Sql error 08003 соединение уже было закрыто dbeaver
  • Sql error 0 sqlstate 42p01