mysql - 创建 mysqldump 以备份数据库

标签 mysql

我知道 mysqldump 是如何工作的。 但是不知道在哪里使用它?

如果我在启动 mysql 程序后执行此命令,则会显示错误。

我正在使用 ubuntu。那么我该如何使用这个实用程序呢?

最佳答案

也用这种方式备份你的数据库..

mysql -u root -p DB_NAME > db_name_backup.sql

如果你想备份所有数据库只需运行这个

mysql -u root -p > mysql_db_backup.sql

您将在此处了解有关 mysql 和 mysqldump 的更多信息..

指南:
mysqldump and mysql
MySQL Database Backup using mysqldump

shell> mysqldump --opt db_name > backup-file.sql

You can read the dump file back into the server like this:

shell> mysql db_name < backup-file.sql

Or like this:

shell> mysql -e "source /path-to-backup/backup-file.sql" db_name

mysqldump is also very useful for populating databases by copying data
from one MySQL server to another:

shell> mysqldump --opt db_name | mysql --host=remote_host -C db_name

It is possible to dump several databases with one command:

shell> mysqldump --databases db_name1 [db_name2 ...] > my_databases.sql

If you want to dump all databases, use the --all-databases option:

shell> mysqldump --all-databases > all_databases.sql

If tables are stored in the InnoDB storage engine, mysqldump provides a
way of making an online backup of these (see command below). This
backup just needs to acquire a global read lock on all tables (using
FLUSH TABLES WITH READ LOCK) at the beginning of the dump. As soon as
this lock has been acquired, the binary log coordinates are read and
lock is released. So if and only if one long updating statement is
running when the FLUSH...  is issued, the MySQL server may get stalled
until that long statement finishes, and then the dump becomes
lock-free. So if the MySQL server receives only short (in the sense of
"short execution time") updating statements, even if there are plenty
of them, the initial lock period should not be noticeable.

shell> mysqldump --all-databases --single-transaction > all_databases.sql

For point-in-time recovery (also known as “roll-forward”, when you need
to restore an old backup and replay the changes which happened since
that backup), it is often useful to rotate the binary log (see
Section 8.4, “The Binary Log”) or at least know the binary log
coordinates to which the dump corresponds:

shell> mysqldump --all-databases --master-data=2 > all_databases.sql
or
shell> mysqldump --all-databases --flush-logs --master-data=2 > all_databases.sql

The simultaneous use of --master-data and --single-transaction works as
of MySQL 4.1.8. It provides a convenient way to make an online backup
suitable for point-in-time recovery if tables are stored in the InnoDB
storage engine.

For more information on making backups, see Section 6.1, “Database
Backups”.

关于mysql - 创建 mysqldump 以备份数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19492819/

相关文章:

mysql - 通过中间 M 进行连接的嵌套查询 :N (MySQL)

mysql - 计算已知深度的层次结构中的值

php - 大型 MySql 查询中的错误

java - 与 Java : How to import an arbitrary . csv 文件中的文件实例函数混淆到 mysql 而不是特定文件?

mysql - 无法通过 MySql 命令行成功更新 Wordpress 管理员密码

Mysql - 检查 VARCHAR 列是否在其增量上有缺失值

php - 从php中选择数据时,MySQL表被锁定多长时间?

mysql - 我怎样才能使这个查询更容易阅读

Mysql访问被拒绝错误1045

php - 如何计算两个日期之间的天数?