错误 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使用哪个数据库:

USE database_name;

在创建表之前。

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

CREATE DATABASE database_name;

紧随其后的是:

USE database_name;

其他回答

注意使用空密码

mysqldump [options] -p '' --databases database_name

将要求密码和抱怨mysqldump:得到错误:1046:“没有数据库选择”时,选择数据库

问题是-p选项要求-p和密码之间没有空格。

mysqldump [options] -p'' --databases database_name

解决了问题(不再需要引号)。

如果导入数据库,则需要先创建同名的数据库,然后选择该数据库,然后将现有数据库导入其中。

希望它对你有用!

当我试图导入以前创建的数据库时,我遇到了同样的错误。以下是我解决这个问题的方法:

创建新的数据库

2—使用Use命令

3-再试一次

这对我很有用。

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

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

虽然这是一个相当老的帖子,但我刚刚发现了一些东西。我创建了一个新数据库,然后添加了一个用户,最后使用phpMyAdmin上传.sql文件。总失败。系统无法识别我所瞄准的DB…

当我开始新的没有首先附加一个新用户,然后执行相同的phpMyAdmin导入,它工作正常。