MySQL错误1046:未选择数据库

时间:2018-02-02 00:04:06

标签: php mysql database

我已经为实验室创建了我的第一个数据库,当我尝试在MySQL中运行它时,我一直得到相同的1046错误:没有选择数据库。

首先,我运行source(scriptfilename).sql并获取:

MariaDB [(none)]> source McClureLab1.sql;
ERROR 1046 (3D000) at line 1 in file: 'McClureLab1.sql': No database selected
ERROR 1046 (3D000) at line 5 in file: 'McClureLab1.sql': No database selected
ERROR 1046 (3D000) at line 12 in file: 'McClureLab1.sql': No database selected
ERROR 1046 (3D000) at line 18 in file: 'McClureLab1.sql': No database selected
+-----------------------------+
| @lastID := LAST_INSERT_ID() |
+-----------------------------+
|                           0 |
+-----------------------------+
1 row in set (0.00 sec)

ERROR 1046 (3D000) at line 21 in file: 'McClureLab1.sql': No database selected
ERROR 1046 (3D000) at line 23 in file: 'McClureLab1.sql': No database selected
+-----------------------------+
| @lastID := LAST_INSERT_ID() |
+-----------------------------+
|                           0 |
+-----------------------------+
1 row in set (0.00 sec)

ERROR 1046 (3D000) at line 26 in file: 'McClureLab1.sql': No database selected
ERROR 1046 (3D000) at line 28 in file: 'McClureLab1.sql': No database selected

当我试图展示我的桌子时,同样的事情发生了:

ERROR 1046 (3D000): No database selected

我不确定我创建的数据库是否有问题,或者我在MySQL中输入的命令是否错误。

1 个答案:

答案 0 :(得分:2)

您是否尝试过首先选择数据库?

USE yourDB;

如果您需要创建它:

创建数据库yourDB;