错误 SQL查询:

--
-- Database: `work`
--
-- --------------------------------------------------------
--
-- Table structure for table `administrators`
--
CREATE TABLE IF NOT EXISTS `administrators` (

`user_id` varchar( 30 ) NOT NULL ,
`password` varchar( 30 ) NOT NULL ) ENGINE = InnoDB DEFAULT CHARSET = latin1;

MySQL说:

#1046 - No database selected

这里需要帮助。


当前回答

MySQL Workbench

通过鼠标右键单击从模式选项卡选择数据库。 将数据库设置为默认模式

其他回答

假设你正在使用命令行:

1. 找到数据库

显示数据库;

2. 从列表中选择一个数据库

使用经典模型;你应该去参加比赛!(显然,您必须在列表中使用正确命名的数据库。

为什么会出现这个错误?

Mysql要求您选择正在使用的特定数据库。我认为这是他们做出的一个设计决策:它避免了很多潜在的问题:例如,你完全有可能在多个数据库中使用相同的表名,例如一个users表。为了避免这类问题,他们可能会想:“让用户选择他们想要的数据库”。

如果你通过phpMyAdmin这样做:

I'm assuming you already Created a new MySQL Database on Live Site (by live site I mean the company your hosting with (in my case Bluehost)). Go to phpMyAdmin on live site - log in to the database you just created. Now IMPORTANT! Before clicking the "import" option on the top bar, select your database on the left side of the page (grey bar, on the top has PHP Myadmin written, below it two options:information_schema and name of database you just logged into. once you click the database you just created/logged into it will show you that database and then click the import option.

这招对我很管用。希望能有所帮助

引用伊万的话: 如果导入数据库,需要先创建一个同名的数据库,然后选择它,然后将现有的数据库导入到它。 希望它对你有用!”

以下是步骤: 创建一个数据库,例如my_db1, utf8_general_ci。 然后单击进入该数据库。 然后点击“导入”,选择数据库:my_db1.sql

应该就这些了。

检查您是否已经首先创建了您想要的数据库。

如果你还没有创建数据库,你必须触发这个查询:

CREATE DATABASE data_base_name

如果你已经创建了数据库,那么你可以简单地启动这个查询,你将能够在你的数据库上创建表:

CREATE TABLE `data_base_name`.`table_name` (
 _id int not null,
 LastName varchar(255) NOT NULL,
 FirstName varchar(255),
 Age int,
 PRIMARY KEY (_id)
);

为了增加安全性,当在同一个脚本中使用多个DB时,您可以在查询中指定DB。创建表my_awesome_db.really_cool_table…