要重新加载由mysqldump生成的包含 SQL 语句的转储文件,可以将其作为输入提供给mysql客户端。如果该转储文件是由mysqldump使用--all-databases或--databases选项创建的,它包含CREATE DATABASE和USE语句,因此无需指定要加载数据的默认数据库:To reload a dump file written by mysqldump
that consists of SQL statements, use it as input to the
mysql client. If the dump file was created by
mysqldump with the
--all-databases or
--databases option, it
contains CREATE DATABASE and
USE statements and it is not
necessary to specify a default database into which to load the
data:
$> mysql < dump.sql
或者,从 mysql 内部,使用 source 命令:Alternatively, from within mysql, use a
source command:
mysql> source dump.sql
如果该文件是单数据库转储且不包含 CREATE DATABASE 和 USE 语句,请先创建数据库(如有必要):If the file is a single-database dump not containing
CREATE DATABASE and
USE statements, create the
database first (if necessary):
$> mysqladmin create db1
然后在加载转储文件时指定数据库名称:Then specify the database name when you load the dump file:
$> mysql db1 < dump.sql
或者,在 mysql 中,创建数据库,将其选为默认数据库,并加载转储文件:Alternatively, from within mysql, create the database, select it as the default database, and load the dump file:
mysql>CREATE DATABASE IF NOT EXISTS db1;mysql>USE db1;mysql>source dump.sql
对于 Windows PowerShell 用户:由于“<”字符在 PowerShell 中被保留以供将来使用,因此需要另一种方法,例如使用引号 cmd.exe /c "mysql
< dump.sql"。For Windows PowerShell users: Because the "<" character is
reserved for future use in PowerShell, an alternative approach
is required, such as using quotes cmd.exe /c "mysql
< dump.sql".