search
HomeDatabaseMysql TutorialMysql备份压缩及恢复数据库方法总结

Mysql备份压缩及恢复数据库方法总结

Jun 07, 2016 pm 04:17 PM
mysqlcompressionbackupSummarizerecoverdatabasemethod

一般情况我们通过mysqldump来备份MySQL数据库,并上传至其它备份机器。如果数据库比较大,在备份传输的时候可能会慢,所以我们尽量让备份的文件小一些。 在写自动备份脚本时,最好把备份结果直接压缩,恢复时也可以直接由压缩备份恢复。下面介绍如何使用bzip

   一般情况我们通过mysqldump来备份MySQL数据库,并上传至其它备份机器。如果数据库比较大,在备份传输的时候可能会慢,所以我们尽量让备份的文件小一些。

  在写自动备份脚本时,最好把备份结果直接压缩,恢复时也可以直接由压缩备份恢复。下面介绍如何使用bzip2和gzip进行压缩mysql备份文件。

  备份并用bzip压缩:

代码如下  

mysqldump | bzip2 > outputfile.sql.bz2

  从bzip2备份恢复:

代码如下  

bunzip2

  备份并用gzip压缩:

代码如下  

mysqldump | gzip > outputfile.sql.gz

  从gzip备份恢复:

  gunzip

  补充本文章

  备份指定数据库

代码如下  

mysqldump -h hostname -u username -p databasename > db.sql不明确指定路径的话被分到用户工作目录:C:Documents and SettingsAdministrator

  可以明确指定备份目录:

代码如下  

mysqldump -u root -p mydb -h 192.168.14.204 > D:mydb.sql

  说明:

  -p之后不用输入密码,点击回车键之后才需要输入密码。

  直接将MySQL数据库压缩备份

代码如下  

mysqldump -h hostname -u username -p databasename | gzip > db.sql.gz

  说明:

  gzip是linux下的压缩工具,,所以在windows环境下无法使用。

  备份MySQL数据库某个(些)表

代码如下  

mysqldump -h hostname -u username -p databasename table1 table2 > db.sql

  同时备份多个MySQL数据库

代码如下  

mysqldump -h hostname -u username -p –databases db1 db2 db3 > dbs.sql

  备份服务器上所有数据库

代码如下  

mysqldump --all-databases > allbackupfile.sql

  测试:

代码如下  

mysqldump --all-databases -u root -p > allbackupfile.sql

  Enter password: ******windows下可以使用Mysql Query Browser的File–》Open Script来执行备份的脚本,同时也可以使用一下命令直接进行恢复:

代码如下  

mysql -h hostname -u username -p databasename

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft