MySQL 如何使用命令提示符恢复 MySQLDump 生成的 SQL 文件

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

How to restore SQL file generated by MySQLDump using command prompt

mysqlmysqldump

提问by Anuya

I have a SQL file generated by MySQLDump. How can I restore it via command prompt?

我有一个由 MySQLDump 生成的 SQL 文件。如何通过命令提示符恢复它?

回答by Nathan

Run this command (if the mysqlexecutable isn't in your PATH, first go to the directory where the MySQL binary is installed, something like \mysql\bin):

运行此命令(如果mysql可执行文件不在您的 中PATH,请首先转到安装 MySQL 二进制文件的目录,例如\mysql\bin):

mysql -u username -ppassword databasename < file.sql

(Note that there is no space between -pand the password)

(注意-p和密码之间没有空格)

Or if the file is gzipped (like my backups mostly are) then something like this:

或者,如果文件是 gzip 压缩的(就像我的备份一样),那么像这样:

gunzip file.sql.gz | mysql -u username -ppassword databasename

or on some systems it might be necessary to add the -cflag to gunzip, like so (to force it to output to stdout):

或者在某些系统上,可能需要将-c标志添加到 gunzip,像这样(强制它输出到标准输出):

gunzip -c file.sql.gz | mysql -u username -ppassword databasename

回答by Xorty

  1. get to bin directory of mysql using command prompt
  2. log in to mysql
  3. run source command with file parameter
  1. 使用命令提示符进入 mysql 的 bin 目录
  2. 登录到mysql
  3. 使用文件参数运行源命令

Example :

例子 :

cd C:\mysql\bin
mysql -u root -p
mysql> source c:\myfile.sql

回答by Edward Dale

$ mysql database < myfile.sql

OR

或者

$ mysql database
mysql> source myfile.sql

回答by Seth

The syntax is:

语法是:

mysql database_name < file.sql

See: Using mysql in Batch Mode

请参阅:在批处理模式下使用 mysql

回答by Mashiro

Assume you are going to import /home/abc.sqlRun commands below:

假设您要导入/home/abc.sql下面的运行命令:

cd /home    
mysql -u root -p

If table not exists:

如果表不存在:

mysql> create database abc;

Now use database abcand import abc.sql

现在使用数据库abc并导入abc.sql

mysql> use abc;
mysql> set names utf8;
mysql> source abc.sql;

回答by Mashiro

From within MySQL command prompt, type

在 MySQL 命令提示符中,键入

SOURCE file.sql