使用命令行恢复 MYSQL 转储文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5429748/
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
Restore MYSQL Dump File with Command Line
提问by Jeaf Gilbert
I have file.sql, and I want to restore it. I found this command:
我有file.sql,我想恢复它。我找到了这个命令:
mysql -u username -p database_name < file.sql
mysql -u username -p database_name < file.sql
Where should I put 'file.sql' in file system? I'm using Windows and XAMPP. Thank you.
我应该将“file.sql”放在文件系统中的什么位置?我正在使用 Windows 和 XAMPP。谢谢你。
*) The dump file is 3GB++
*) 转储文件为 3GB++
采纳答案by Jeaf Gilbert
When I execute the answers of this thread, it returns 'mysql' is not recognized as an internal or external command, operable program or batch file.
.
当我执行这个线程的答案时,它返回'mysql' is not recognized as an internal or external command, operable program or batch file.
.
Turned out that I have to execute mysql.exe first in xampp/mysql/bin folder, and the dump file path is relative to this bin folder. I put mine in there, and it worked.
原来我要先在xampp/mysql/bin文件夹中执行mysql.exe,转储文件路径是相对于这个bin文件夹的。我把我的放在那里,它奏效了。
Thanks all.
谢谢大家。
回答by Peter Lindqvist
You can put it anywhere, where there is enough diskspace available of course.
你可以把它放在任何地方,当然,只要有足够的可用磁盘空间。
A good place for this would be either /tmp
(on linux or similar) or c:\temp
(on windows or similar)
一个很好的地方是/tmp
(在 linux 或类似平台上)或c:\temp
(在 windows 或类似平台上)
But assuming you use that exact line you need to change your working directory to that which holds the file.
但是假设您使用该行,您需要将工作目录更改为保存文件的目录。
cd /path/where/sql/file/is
And then
进而
mysql -u username -p database_name < file.sql
If you don't have the mysql bin in your PATH you might want to run
如果您的 PATH 中没有 mysql bin,您可能想要运行
/path/to/mysql/bin/mysql -u username -p database_name < file.sql
Or temporarily put the file.sql in the mysql bin directory (not recommended)
或者暂时把file.sql放到mysql bin目录下(不推荐)
Another possible scenario is to point to the file in the filesystem like this
另一种可能的情况是像这样指向文件系统中的文件
mysql -u username -p database_name < /path/where/sql/file/is/file.sql
PS. If you're on windows you might wanna change the forward slashes to backslashes.
附注。如果您在 Windows 上,您可能想将正斜杠更改为反斜杠。
回答by Shakti Singh
You can put anywhere in the system but consider to change the command also
您可以放置在系统中的任何位置,但也要考虑更改命令
mysql -u username -p database_name < /somepath/file.sql
回答by user3556600
Type the following command to import sql data file:
输入以下命令导入sql数据文件:
$ mysql -u username -p -h localhost DATA-BASE-NAME < data.sql
In this example, import 'data.sql' file into 'blog' database using vivek as username:
在此示例中,使用 vivek 作为用户名将“data.sql”文件导入“blog”数据库:
$ mysql -u sat -p -h localhost blog < data.sql
If you have a dedicated database server, replace localhost hostname with with actual server name or IP address as follows:
如果您有专用的数据库服务器,请将 localhost 主机名替换为实际的服务器名称或 IP 地址,如下所示:
$ mysql -u username -p -h 202.54.1.10 databasename < data.sql
OR use hostname such as mysql.cyberciti.biz
或使用主机名,例如 mysql.cyberciti.biz
$ mysql -u username -p -h mysql.cyberciti.biz database-name < data.sql
If you do not know the database name or database name is included in sql dump you can try out something as follows:
如果您不知道数据库名称或数据库名称包含在 sql dump 中,您可以尝试以下操作:
$ mysql -u username -p -h 202.54.1.10 < data.sql
Refer: http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html
回答by Pritam Chaudhari
Import Database
1. Go to drive
command: d:
2. Mysql login
command: c:\xampp\mysql\bin\mysql -u root -p
3. Will ask for pwd: enter it
pwd
4. Select db
use DbName;
5. Provide file name
\. G:DbName.sql
回答by Gajendra Bang
The best option will be
最好的选择将是
1) open the command prompt by Start -> Run -> Command or anyway 2) change you directory where the file.sql is saved say C:\temp\file.sql so your command prompt should look like
1) 通过开始 -> 运行 -> 命令或其他方式打开命令提示符 2) 更改保存 file.sql 的目录,例如 C:\temp\file.sql,因此您的命令提示符应如下所示
C:\temp>
3) now try these command
3)现在试试这些命令
mysql -u root -p database_name < file.sql
回答by Matteo Alessani
you need to point to the location of your file using:
您需要使用以下命令指向文件的位置:
mysql -u username -p database_name < drive:\path_to_your_file\file.sql
回答by Devart
As an alternate, try to restore the dump with a Restore or with an Execute Large Script Wizard Wizard.
作为替代方法,尝试使用“还原”或“执行大脚本向导”来还原转储。
There is a command-line support.
有命令行支持。
回答by Deepak Saxena
You can restore the dump using phpmyadmin as well but you have to sure that it must be .sql file.
您也可以使用 phpmyadmin 恢复转储,但您必须确保它必须是 .sql 文件。
The second way is if you are linux user than use the command line to restore the dump file.
第二种方法是,如果您是 linux 用户,则不要使用命令行来恢复转储文件。
mysql> mysql -uuser_name -ppassword table_name < /path/to/dump_file.sql
mysql> mysql -uuser_name -ppassword table_name < /path/to/dump_file.sql