MySQL 如何导入 .sql 文件

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

How to import a .sql file

mysqlsqlimportubuntu-10.04

提问by Margherita

I'm running MySQL on Ubuntu 10.4 LTS and unfortunately I've been experiencing serious problems when it comes to importing a sql file.

我在 Ubuntu 10.4 LTS 上运行 MySQL,不幸的是我在导入 sql 文件时遇到了严重的问题。

What I actually do:

我实际做的:

1) I move to the directory containing the sql file which is called: bk.sql

1)我移动到包含名为的sql文件的目录:bk.sql

2) Then I type :

2)然后我输入:

mysql -u root -p(and then I enter the root password and everything goes smoothly)

mysql -u root -p(然后我输入root密码,一切顺利)

3) I use this command to do the import operation (assuming that password =123m Database name = Mydb sql file = bk.sql)

3)我用这个命令做导入操作(假设密码=123m 数据库名=Mydb sql文件=bk.sql)

mysql -u root -p 123m Mydb < bk.sql;

What I get is :

我得到的是:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that 

corresponds to your MySQL server version for the right syntax to use near 'mysql -u root 

-p 123m Mydb < bk.sql' at line 1

Is the import procedure correct?

进口流程是否正确?

回答by dogbane

It looks like you are running the mysql import command from the mysql prompt which is not right.

看起来您正在从 mysql 提示符运行 mysql import 命令,这是不对的。

You don't need to do step 2. Just do steps 1 and 3.

您不需要执行第 2 步。只需执行第 1 步和第 3 步。

回答by Shritam Bhowmick

Do this, and you will have it.

这样做,你就会拥有它。

mysql -u root -ptoor -h localhost database_in_mysql < local_sql_file.sql
mysql> show databases;

mysql> use meow;
mysql> select * from customers_meow;

and you'll see all the tables, bingo ! ch33rs.

你会看到所有的桌子,宾果游戏!ch33rs。

回答by Kavin D

First enter this.. in cmd or terminal...

首先在cmd或终端中输入这个..

mysql -u root -p Mydb < bk.sql

Then it ask password

然后它询问密码

Password : 123m

Now wait .. i will take several time .. thats all...

现在等等..我需要一些时间..仅此而已......