windows下如何使用mysql的source命令导入大文件

2021-12-25 00:00:00 import xampp mysql

我有一个大 (~150mb) 的 sql 文件要导入.它太大了,无法通过 PHPMyAdmin 完成,甚至将其拆分为许多部分,而且它太大而无法通过 php 脚本导入,因为它在处理脚本 30 秒后超时.所以我正在寻找如何从 MySQL 命令行直接导入文件.

I have a large (~150mb) sql file that I am trying to import. It is too large to do it through PHPMyAdmin even splitting it into many pieces and it is too large to import through a php script as it times out after 30 seconds of processing the script. So I'm looking for how to directly import the file from MySQL command line.

在线搜索显示我想使用 database_name <file_name.sqlsource file_name.sql 但我无法使用其中任何一个.

Searching online shows that I want to either use database_name < file_name.sql or source file_name.sql but I can't get either of these to work.

使用 < 给出了通用的 MySQL 语法错误,而使用 source 给出了一个稍微更有希望的 failed to open file 'file_name.sql', error: 2 所以我倾向于认为 source 命令是在正确的轨道上.

Using < gives the generic MySQL syntax error while using source give a slightly more promising failed to open file 'file_name.sql', error: 2 so I am inclined to think that the source command is on the right track.

我在 Windows 中并且使用 xampp 作为本地主机服务器(请注意,我只是尝试在本地主机上导入此文件,以便我可以执行 sql).我尝试将文件放在 xamppmysqlinxamppmysqldatadatabase_name 中.

I am in windows and am using xampp as a localhost server (note I'm only trying to import this file on the localhost so that I can execute the sql). I've tried placing the file in xamppmysqlin and xamppmysqldatadatabase_name.

关于如何从 MySQL 命令行或通过任何其他方式将此 .sql 文件导入 MySQL 的任何建议将不胜感激.

Any suggestions of how to import this .sql file into MySQL either from the MySQL command line or by any other means would be greatly appreciated.

推荐答案

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

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

C:xamppmysqlinmysql -u {username} -p {databasename} < file_name.sql

相关文章