错误 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

这里需要帮助。


当前回答

如果你通过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.

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

其他回答

MySQL Workbench

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

在Amazon RDS中,如果数据库名称中包含破折号,那么仅仅写use my-favorite-database是行不通的。此外,以下工作也均未完成:

use "my-favorite-database"
use `my-favorite-database`
use 'my-favorite-database'

只需点击“更改数据库”按钮,选择所需的数据库,然后点击voilà。

如果您试图通过命令行完成此操作…

如果你试图从命令行界面运行CREATE TABLE语句,你需要在执行查询之前指定你正在使用的数据库:

USE your_database;

这是文档。

如果你试图通过MySQL Workbench来做这件事…

...你需要在:Object Browser:选项卡上方的下拉菜单中选择适当的数据库/目录。您可以为连接指定默认的模式/数据库/目录—单击Workbench启动屏幕的SQL Development标题下的“Manage Connections”选项。

齿顶高

这一切都假设有一个数据库,你想要在其中创建表-如果不是,你需要在其他任何事情之前创建数据库:

CREATE DATABASE your_database;

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

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

应该就这些了。

你需要告诉MySQL使用哪个数据库:

USE database_name;

在创建表之前。

如果数据库不存在,您需要将其创建为:

CREATE DATABASE database_name;

紧随其后的是:

USE database_name;