使用 MySQL WorkBench 导入...错误 ERROR 1046 (3D000)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5787130/
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 19:39:16  来源:igfitidea点击:

Importing using MySQL WorkBench... error ERROR 1046 (3D000)

mysqlmysql-error-1046

提问by RedCuber

Scenario: building a RoR enviroment locally for development. Production is on EngineYard / GitHub. All now working ok, except DB isn't importing.

场景:在本地构建一个 RoR 环境进行开发。生产在 EngineYard / GitHub 上。现在一切正常,除了数据库没有导入。

I have a .sql file that i've taken from my prod EY site. Now i need to import it to my MySQL locally. I'm using Workbench (as i'm new to this), but getting error below.

我有一个从我的 prod EY 站点获取的 .sql 文件。现在我需要将它本地导入到我的 MySQL 中。我正在使用 Workbench(因为我是新手),但在下面出现错误。

Please help?

请帮忙?

08:07:43 Restoring /home/james/Downloads/Futology.sql Running: mysql --defaults-extra-file="/tmp/tmpAVeE58/extraparams.cnf" --host=localhost --user=root --port=3306 --default-character-set=utf8 --comments < "/home/james/Downloads/Futology.sql" ERROR 1046 (3D000) at line 22: No database selected

Operation failed with exitcode 1 08:07:43 Import of /home/james/Downloads/Futology.sql has finished with 1 errors

08:07:43 恢复 /home/james/Downloads/Futology.sql 运行:mysql --defaults-extra-file="/tmp/tmpAveE58/extraparams.cnf" --host=localhost --user=root --port =3306 --default-character-set=utf8 --comments < "/home/james/Downloads/Futology.sql" 第 22 行出现错误 1046 (3D000):未选择数据库

操作失败,退出代码 1 08:07:43 导入 /home/james/Downloads/Futology.sql 已完成 1 个错误

回答by Brad Hunter

Workbench doesn't know the database (schema) you want to use.

Workbench 不知道您要使用的数据库(架构)。

In workbench, when using Data Import/Restore, just below where you choose the file to import, it asks "Default Schema to be Imported To"

在工作台中,当使用数据导入/恢复时,就在您选择要导入的文件的下方,它会询问“要导入到的默认架构”

Just choose the database (schema) you want it to use from the dropdown titled Default Target Schema. If you don't have a database (schema) already, you can create it with the "New" button.

只需从标题为“默认目标架构”的下拉列表中选择您希望它使用的数据库(架构)。如果您还没有数据库(架构),您可以使用“新建”按钮创建它。

This is confusing because MySQL generally seems to use the term database but Workbench uses schema. They mean the same thing for most purposes. MySQL 'create schema' and 'create database' - Is there any difference

这令人困惑,因为 MySQL 通常似乎使用术语数据库,而 Workbench 使用模式。对于大多数目的,它们的含义相同。MySQL“创建架构”和“创建数据库”-有什么区别

回答by charliequinn

Not used Workbench too much however it's easy enough to do from command line have a look at this(below phpMyAdmin instructions)

没有使用太多的 Workbench 但是从命令行很容易做看看这个(在 phpMyAdmin 说明下面)

The command you're after is: mysql -u #username# -p #database# < #dump_file#

您要执行的命令是: mysql -u #username# -p #database# < #dump_file#

回答by Chuqi Cha

Simply by choosing your target schema

只需选择您的目标架构

Simply by choosing your target schema

只需选择您的目标架构

As I circled in above image

正如我在上图中圈出的那样

回答by Kirk Woll

Similar to brynn's answer, simply modify your SQL file and insert the following line at the very top:

与 Brynn 的回答类似,只需修改您的 SQL 文件并在最顶部插入以下行:

use yourdatabasename

Replacing yourdatabasenamewith the database into which you are trying to import. Also, this database should already be created (albeit empty) before you import into it.

替换yourdatabasename为您尝试导入的数据库。此外,在导入之前应该已经创建了这个数据库(尽管是空的)。

回答by brynn

Here's another option that worked for me. I'm using MySQL 5.5 on a VM I set up for importing a large MySQL .sql dump that contained: 1). a create table statement 2). insert statements for inserting a large amount of data into the table. at the MySQL command line client prompt type:

这是另一个对我有用的选项。我在为导入大型 MySQL .sql 转储而设置的 VM 上使用 MySQL 5.5,其中包含:1)。创建表语句 2)。用于向表中插入大量数据的插入语句。在 MySQL 命令行客户端提示符下键入:

use yourdatabasename
source d:\yourpath\yourfilename.sql

for more info on the 'source' and other commands, enter ? at the prompt.

有关“源”和其他命令的更多信息,请输入 ? 在提示下。

回答by steve

The above command line is correct. I found I have to do this when importing .sql files from older versions of MySQL. I also found I had to edit the .sql file (top of the file) and set the db name to be the same as the blank db you create before doing the import.

上面的命令行是正确的。我发现从旧版本的 MySQL 导入 .sql 文件时必须这样做。我还发现我必须编辑 .sql 文件(文件顶部)并将数据库名称设置为与导入之前创建的空白数据库相同。