在Linux中使用Mysqldump备份和还原MySQL数据库 您所在的位置:网站首页 linux下备份文件命令 在Linux中使用Mysqldump备份和还原MySQL数据库

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

2024-07-17 10:24| 来源: 网络整理| 查看: 265

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



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

      专题文章
        CopyRight 2018-2019 实验室设备网 版权所有