Home > Database > Mysql Tutorial > MySQL Bug - #1046 - No database selected

MySQL Bug - #1046 - No database selected

王林
Release: 2023-08-26 17:33:16
forward
1801 people have browsed it

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)
-> );
Copy after login

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;
Copy after login

Below is the output −

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

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
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template