如何创建单个数据库的转储?

How to create dump of a single database?

我正在使用 64 位 wampserver。我通过 wamp 托盘菜单图标启动 MySQL 控制台并执行此命令,如 documentation.

中所示
mysqldump magento_live > dump.sql;

结果:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysqldump magento_live > dump.sql' at line 1

这个我也试过answer:

mysqldump -u root -p root -h localhost magento_live > magentoLiveDump.sql;

结果:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysqldump -u root -p root -h localhost magento_live > magentoLiveDump.sql' at line 1

我正在使用 MySQL 5.7


我使用以下命令通过 CMD 进行了尝试:

C:\wamp64\bin\mysql\mysql5.7.21\bin>C:\wamp64\bin\mysql\mysql5.7.21\bin\mysql.exe mysqldump magento_live > test.sql

文件已创建,但这是内容:

C:\wamp64\bin\mysql\mysql5.7.21\bin\mysql.exe Ver 14.14 Distrib 5.7.21, for Win64 (x86_64) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Usage: C:\wamp64\bin\mysql\mysql5.7.21\bin\mysql.exe [OPTIONS] [database] -?, --help Display this help and exit. -I, --help Synonym for -? --auto-rehash Enable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time. Disable with --disable-auto-rehash. (Defaults to on; use --skip-auto-rehash to disable.) -A, --no-auto-rehash

[...]

命令 mysqldump 不会从 MySQL CLI 中 运行,您必须从 windows 命令提示符 (CMD) 中 运行 或来自 Powershell。

您必须启动 CMD 或 Powershell 并导航到 MySQL 目录中的 bin 文件夹 (wamp64\bin\mysql\mysql5.7.21\bin).

然后你必须执行这样的命令:

mysqldump -u[USERNAME] -p target_database > target_dump_name.sql

重要提示:选项和值之间不允许有space。

错误mysqldump -u root -p target_database > target_dump_name.sql

正确mysqldump -uroot -p target_database > target_dump_name.sql


例子

CMD:

mysqldump -uroot -p magento_live > magento_live_dump.sql

Powershell:

.\mysqldump -uroot -p magento_live > magento_live_dump.sql

注意:在Powershell中,您必须在命令前添加.\