8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

9.4.2 重新加载 SQL 格式备份9.4.2 Reloading SQL-Format Backups

要重新加载由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
Note

对于 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".