在Linux中使用Mysqldump备份和还原MySQL数据库

本文介绍了如何使用mysqldump工具在Linux环境中备份和恢复MySQL数据库。内容涵盖备份单个和多个数据库、备份所有数据库、备份单表、备份到远程服务器、仅备份数据库架构、压缩备份以及恢复数据库的操作步骤和相关选项。
摘要由CSDN通过智能技术生成

One of the most important task of a database administrator is backing up and restoring databases. MySQL is a popular database server and provides tool named mysqldump for backup and restore operations. We will look different usage types of mysqldump in this tutorial.

数据库管理员最重要的任务之一就是备份和还原数据库。 MySQL是一种流行的数据库服务器,并提供名为mysqldump工具用于备份和还原操作。 在本教程中,我们将介绍mysqldump的不同用法类型。

句法 (Syntax)

mysqldump [OPTIONS] database [tables] 
OR     
mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...] 
OR     
mysqldump [OPTIONS] --all-databases [OPTIONS]

帮帮我 (Help)

$ mysqldump --help
Help
Help
帮帮我

连接远程数据库服务器(Connect Remote Database Server)

By default mysqldump will try to connect local MySQL server database. Remote databases server can be specified with -h option as IP address or domain name. In this example we will try to connect host named poftut1 .

默认情况下,mysqldump将尝试连接本地MySQL服务器数据库。 可以使用-h选项将远程数据库服务器指定为IP地址或域名。 在此示例中,我们将尝试连接名为poftut1主机。

$ mysqldump -h poftut1 -u root -p  mysql > back.sql

备份单个数据库 (Backup Single Database)

Mysqldump have a lot of usage possibilities but the most popular one is backing up single database. This will only backup single specified database. We will specify user name and password with database name. Username will be specified with -u options and password specified with -p option. We will specify database name after these information without an option.

Mysqldump有很多使用可能性,但是最流行的一种是备份单个数据库。 这将仅备份单个指定的数据库。 我们将使用数据库名称指定用户名和密码。 用-u选项指定用户名,用-p选项指定密码。 我们将在这些信息之后指定数据库名称,而无需任何选择。

$ mysqldump -u root -p mysql > mysql.sql
Backup Single Database
Backup Single Database
备份单个数据库

By default backup output is written to the standard output. But in this example we have redirected the output to the file named mysql.sql . the backup file is an sql file which holds sql schemas and data.

默认情况下,备份输出将写入标准输出。 但是在此示例中,我们将输出重定向到名为mysql.sql的文件。 备份文件是一个sql文件,其中包含sql模式和数据。

备份多个数据库 (Backup Multiple Databases)

We can backup multiple databases just adding more databases to the end of the mysqldump command. In this example we will backup databases mysql , sys . We will use --databases

  • 3
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值