MySQL phpMyadmin 数据库导入错误 #1046 - 未选择数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6880511/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:41:41  来源:igfitidea点击:

phpMyadmin database import error #1046 - No database selected

mysqldatabaseimportphpmyadmin

提问by user780483

I have an sql file that i exported from phpmyadmin on another computer. I tried to import the file on this computer and I get this error:

我有一个从另一台计算机上的 phpmyadmin 导出的 sql 文件。我试图在这台计算机上导入文件,但出现此错误:

Error

SQL query:

SQL查询:

--
-- Database: `phplogin`
--
-- --------------------------------------------------------
--
-- Table structure for table `people`
--
CREATE TABLE IF NOT EXISTS  `people` (

 `id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
 `name` VARCHAR( 25 ) NOT NULL ,
 `age` INT( 11 ) NOT NULL ,
 `testvar` VARCHAR( 5 ) NOT NULL ,
PRIMARY KEY (  `id` )
) ENGINE = MYISAM DEFAULT CHARSET = latin1 AUTO_INCREMENT =3;

MySQL said: 

#1046 - No database selected 

回答by Clowerweb

The error is because you either didn't select a database on the left side to import to, and/or you didn't create the empty database first. Create a database in phpMyAdmin called "phplogin", select it on the left side, and then run the import.

错误是因为您没有在左侧选择要导入的数据库,和/或您没有先创建空数据库。在phpMyAdmin中创建一个名为“phplogin”的数据库,在左侧选择它,然后运行导入。

回答by funtime

Append the following line to the beginning of your sql file

将以下行追加到 sql 文件的开头

CREATE DATABASE phplogin;

These problems can be resolved by exporting the SQL file while being outside the database.Then phpmyadmin automatically appends the above statement to the SQL file

这些问题可以通过在数据库外导出SQL文件来解决。 然后phpmyadmin自动将上述语句附加到SQL文件中

回答by TenLeftFingers

I've had this problem just this moment and none of the above answers solved my problem. Eventually, I ran the export again and the resulting .sql file was much larger. So the problem was a faulty export which resulted in an incomplete SQL file. The necessary statements would have been truncated in this case.

此刻我遇到了这个问题,上述答案都没有解决我的问题。最终,我再次运行导出,生成的 .sql 文件要大得多。所以问题是导出错误导致 SQL 文件不完整。在这种情况下,必要的语句将被截断。