MySQL 在 Windows 7 中通过命令行导入 SQL 文件

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

Import SQL file by command line in Windows 7

mysqlphpmyadmincommand-line-argumentswampserver

提问by Napster

I want to import an SQL file (size > 500MB) into a database. I have wamp on my PC. Phpmyadmin does not work well with this size. I changed all parameters in php.ini (max_upload_size etc.). But it does not work for me. So I want to import it by command line.

我想将一个 SQL 文件(大小 > 500MB)导入到数据库中。我的电脑上有 wamp。phpmyadmin 不能很好地处理这种大小。我更改了 php.ini 中的所有参数(max_upload_size 等)。但它对我不起作用。所以我想通过命令行导入它。

I used these commands for import the file:

我使用这些命令导入文件:

mysql -u root -p sysdat < D:\Nisarg\ISPC\Database\sysdat.sql 
mysql -u root -p -D sysdat < D:\Nisarg\ISPC\Database\sysdat.sql
mysql -u root sysdat < D:\Nisarg\ISPC\Database\sysdat.sql -p 

These all are not working.

这些都行不通。

回答by user2001117

Try like this:

像这样尝试:

I think you need to use the full path at the command line, something like this, perhaps:

我认为您需要在命令行中使用完整路径,例如:

C:\xampp\mysql\bin\mysql -u {username} -p {databasename} < file_name.sql

Refer this link also:

另请参阅此链接:

http://www.ryantetek.com/2011/09/importing-large-sql-files-through-command-line-when-using-phpmyadminxampp/

http://www.ryantetek.com/2011/09/importing-large-sql-files-through-command-line-when-using-phpmyadminxampp/

回答by sqlchild

If you have wamp installed then go to command prompt , go to the path where mysql.exe exists , like for me it was : C:\wamp\bin\mysql\mysql5.0.51b\bin , then paste the sql file in the same location and then run this command in cmd :

如果您安装了 wamp,则转到命令提示符,转到 mysql.exe 所在的路径,就像我一样: C:\wamp\bin\mysql\mysql5.0.51b\bin ,然后将 sql 文件粘贴到相同的位置,然后在 cmd 中运行此命令:

C:\wamp\bin\mysql\mysql5.0.51b\bin>mysql -u root -p YourDatabaseName < YourFileName.sql

回答by Nanhe Kumar

To import database from dump file use:

要从转储文件中导入数据库,请使用:

mysql -u UserName -p Password DatabaseName < FileName.sql 

In wamp

在 wamp

C:\wamp\bin\mysql\mysql5.0.51b\bin>mysql mysql -uroot -p DatabaseName < FileName.sql 

回答by Minhphuong Le

----------------WARM server.

----------------暖服务器。

step 1: go to cmd go to directory C:\wamp\bin\mysql\mysql5.6.17 hold Shift + right click (choose "open command window here")

第一步:进入cmd进入目录C:\wamp\bin\mysql\mysql5.6.17按住Shift+右键(选择“在此处打开命令窗口”)

step 2: C:\wamp\bin\mysql\mysql5.6.17\bin>mysql -u root -p SellProduct < D:\file.sql

第二步:C:\wamp\bin\mysql\mysql5.6.17\bin>mysql -u root -p SellProduct < D:\file.sql

in this case
+ Root is username database  
+ SellProduct is name database.
+ D:\file.sql is file you want to import

---------------It's work with me -------------------

---------------它和我一起工作 -------------------

回答by Shal

TRY THIS

尝试这个

  C:\xampp\mysql\bin\mysql -u {username} -p {databasename} < {filepath}

if username=root ,filepath='C:/test.sql', databasename='test' ,password ='' then command will be

如果 username=root ,filepath='C:/test.sql', databasename='test' ,password='' 那么命令将是

  C:\xampp\mysql\bin\mysql -u root  test < C:/test.sql

回答by Shusen Yi

I use mysql -u root -ppassword databasename < filename.sqlin batch process. For an individual file, I like to use sourcemore because it shows the progress and any errors like

mysql -u root -ppassword databasename < filename.sql在批处理中使用。对于单个文件,我喜欢使用source更多,因为它显示了进度和任何错误,例如

Query OK, 6717 rows affected (0.18 sec)
Records: 6717  Duplicates: 0  Warnings: 0
  1. Log in to MySQL using mysql -u root -ppassword
  2. In MySQL, change the database you want to import in: mysql>use databasename;

    • This is very important otherwise it will import to the default database
  3. Import the SQL file using source command: mysql>source path\to\the\file\filename.sql;

  1. 使用登录到 MySQL mysql -u root -ppassword
  2. 在 MySQL 中,更改要导入的数据库: mysql>use databasename;

    • 这很重要,否则它会导入到默认数据库
  3. 使用 source 命令导入 SQL 文件: mysql>source path\to\the\file\filename.sql;

回答by Chirag Shah

To import database from dump file (in this case called filename.sql)

从转储文件导入数据库(在本例中称为 filename.sql)

    use: mysql -u username -p password database_name < filename.sql 

you are on Windows you will need to open CMD and go to directory where mysql.exe is installed. you are using WAMP server then this is usually located in: C:\wamp\bin\mysql\mysql5.5.8\bin (*note the version of mysql might be different)

您使用的是 Windows,您需要打开 CMD 并转到安装 mysql.exe 的目录。您使用的是 WAMP 服务器,那么它通常位于:C:\wamp\bin\mysql\mysql5.5.8\bin (*注意 mysql 的版本可能不同)

So you will: cd C:\wamp\bin\mysql\mysql5.5.8\bin

所以你会: cd C:\wamp\bin\mysql\mysql5.5.8\bin

and then execute one of the above commands. Final command like this

然后执行上述命令之一。像这样的最终命令

    C:\wamp\bin\mysql\mysql5.5.8\bin>mysql -u rootss -p pwdroot testdatabasename < D:\test\Projects\test_demo_db.sql

回答by Chetan

Try this it will work. Do not enter password it will ask one you execute the following cmd

试试这个它会起作用。不要输入密码它会要求你执行以下cmd

C:\xampp\mysql\bin\mysql -u xxxxx -p -h localhost your_database_name < c:\yourfile.sql

回答by naveen J

mysql : < (for import) > (for export)

mysql : <(用于导入)>(用于导出)

in windows, you want to take backup or import the sql file, then goto cmd prompt type the address were the mysql is installed eg:C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin> after this

在windows中,你要备份或导入sql文件,然后到cmd提示符输入mysql安装的地址eg:C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin> 之后

C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin> mysql -u UserName -p Password DatabaseName < FileName.sql (import)

C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin> mysql -u UserName -p Password DatabaseName < FileName.sql (import)

C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin> mysql -u UserName -p Password DatabaseName > FileName.sql (export)

C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin> mysql -u UserName -p Password DatabaseName > FileName.sql(导出)

回答by Rob Evans

Related to importing, if you are having issues importing a file with bulk inserts and you're getting MYSQL GONE AWAY, lost connection or similar error, open your my.cnf / my.ini and temporarily set your max_allowed_packet to something large like 400M

与导入相关,如果您在导入带有批量插入的文件时遇到问题,并且出现 MYSQL GONE AWAY、连接丢失或类似错误,请打开 my.cnf / my.ini 并暂时将 max_allowed_pa​​cket 设置为 400M 之类的大文件

Remember to set it back again after your import!

导入后记得重新设置!