Home  >  Article  >  Database  >  MySQL Bug - #1046 - No database selected

MySQL Bug - #1046 - No database selected

王林
王林forward
2023-08-26 17:33:161689browse

Error #1046 may occur when we create a table but forget to select a database. let We say that we have started MySQL as shown below −

MySQL 错误 - #1046 - 未选择数据库

After entering the correct password, the above window will open. Now create one without Choose any database. This will display an error −

mysql> CREATE table TblUni
-> (
-> id int,
-> Name varchar(100)
-> );

Error 1046 (3D000): No database selected

The following screenshot shows the same error-

MySQL 错误 - #1046 - 未选择数据库

Now, select any database to eliminate the above error. First let's see how many there are The database appears in MySQL with the help of SHOW command -

mysql> SHOW databases;

Below is the output −

+--------------------+
| Database           |
+--------------------+
| business           |
| hello              |
| information_schema |
| mybusiness         |
| mysql              |
| performance_schema |
| sample             |
| sys                | 
| test               |
+--------------------+
9 rows in set (0.00 sec)

Now, we can select any database. Let's say I use the database "business" so we This can be selected via the "use" command.

mysql> use business;
Database changed

After using the database "business", we can create the above table without any errors.

mysql> CREATE table TblUni
-> (
-> id int,
-> Name varchar(100)
-> );
Query OK, 0 rows affected (0.50 sec)

The above is the detailed content of MySQL Bug - #1046 - No database selected. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete