Home Database Mysql Tutorial MySQL数据库备份和还原的常用命令小结

MySQL数据库备份和还原的常用命令小结

Jun 07, 2016 pm 06:06 PM
database backup reduction

MySQL数据库备份和还原的常用命令小结,学习mysql的朋友可以参考下

备份MySQL数据库的命令

mysqldump -hhostname -uusername -ppassword databasename > backupfile.sql
Copy after login

备份MySQL数据库为带删除表的格式备份MySQL数据库为带删除表的格式,能够让该备份覆盖已有数据库而不需要手动删除原有数据库。

mysqldump ---add-drop-table -uusername -ppassword databasename > backupfile.sql
Copy after login

直接将MySQL数据库压缩备份

mysqldump -hhostname -uusername -ppassword databasename | gzip > backupfile.sql.gz
Copy after login

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

mysqldump -hhostname -uusername -ppassword databasename specific_table1 specific_table2 > backupfile.sql
Copy after login

同时备份多个MySQL数据库

mysqldump -hhostname -uusername -ppassword --databases databasename1 databasename2 databasename3 > multibackupfile.sql
Copy after login

仅仅备份数据库结构

mysqldump --no-data --databases databasename1 databasename2 databasename3 > structurebackupfile.sql
Copy after login

备份服务器上所有数据库

mysqldump --all-databases  allbackupfile.sql
Copy after login

还原MySQL数据库的命令

mysql -hhostname -uusername -ppassword databasename 
<p><strong>还原压缩的MySQL数据库</strong></p>

<pre class="brush:php;toolbar:false">gunzip 
<p><strong>将数据库转移到新服务器</strong></p>

<pre class="brush:php;toolbar:false">mysqldump \-uusername \-ppassword databasename \| mysql \--host=*.*.*.\* \-C databasename
Copy after login

压缩备份

备份并用gzip压缩:

mysqldump  | gzip > outputfile.sql.gz
Copy after login

从gzip备份恢复:

gunzip 
Copy after login

备份并用bzip压缩:

mysqldump  | bzip2 > outputfile.sql.bz2
Copy after login

从bzip2备份恢复:

bunzip2  
Copy after login
Statement of this Website
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

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 Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

Tutorial: How to restore the Win7 taskbar to the bottom Tutorial: How to restore the Win7 taskbar to the bottom Jan 02, 2024 pm 09:05 PM

When we use win7 system, sometimes we accidentally drag the taskbar to the left or right, which looks very uncomfortable and affects the use. In fact, the restoration method is very simple. Just drag it back or change the settings in the properties. Let’s take a look. Restore the win7 taskbar to the following tutorial method one: 1. First, right-click the taskbar and make sure the taskbar is not locked. If it is locked, click Unlock. 2. Left-click an empty space on the taskbar, hold down the left mouse button, and drag downwards to drag the taskbar back. 3. It should be noted that due to the screen size, dragging the taskbar will change the size of the taskbar. Move the mouse to the edge of the taskbar and drag up or down to set the appropriate size. square

PHP and PDO: How to perform database backup and restore operations PHP and PDO: How to perform database backup and restore operations Jul 29, 2023 pm 06:54 PM

PHP and PDO: How to perform database backup and restore operations When developing web applications, database backup and restore are very important tasks. As a popular server-side scripting language, PHP provides a wealth of libraries and extensions, among which PDO (PHP Data Objects) is a powerful database access abstraction layer. This article will introduce how to use PHP and PDO to perform database backup and restore operations. Step 1: Connect to the database Before actual operation, we need to establish a connection to the database. Use PDO pair

Analysis of project experience on MySQL database backup and recovery performance optimization Analysis of project experience on MySQL database backup and recovery performance optimization Nov 02, 2023 am 08:53 AM

In the current Internet era, the importance of data is self-evident. As one of the core components of Internet applications, database backup and recovery work is particularly important. However, as the amount of data continues to increase and business requirements become increasingly complex, traditional database backup and recovery solutions can no longer meet the high availability and high performance requirements of modern applications. Therefore, optimizing the backup and recovery performance of MySQL database has become an urgent problem that needs to be solved. In practice, we have adopted a series of project experiences to effectively improve MySQL data

How to use ThinkPHP6 to implement database backup and recovery How to use ThinkPHP6 to implement database backup and recovery Jun 20, 2023 pm 07:25 PM

In the process of developing business systems, the database is a very important part. Therefore, backing up and restoring the database is a very necessary operation. This article will combine examples of the ThinkPHP6 framework to introduce how to use ThinkPHP6 to implement database backup and recovery. 1. Database backup 1.1 Environment preparation Before performing database backup, you need to confirm the following points: 1. You need to set the bin directory address of the mysql database and add its path to the system Path variable; 2. Mysqld needs to be installed

How to backup database in Golang? How to backup database in Golang? Jun 01, 2024 am 11:56 AM

Backing up your database in Golang is crucial to protecting your data. You can use the database/sql package in the standard library, or a third-party package such as github.com/go-sql-driver/mysql. Specific steps include: Connect to the database. Create a file to store the backup data. Use the Dump function or Exporter to back up the database to a file.

How to use thinkorm to implement database backup and restore How to use thinkorm to implement database backup and restore Jul 28, 2023 pm 02:05 PM

Title: Using ThinkORM to realize database backup and restoration Introduction: In the development process, database backup and restoration is a very important task. This article will introduce how to use the ThinkORM framework to implement database backup and restoration, and provide corresponding code examples. 1. Background introduction During the development process, we usually use databases to store and manage data. The principle of database backup and restore is to perform regular backups of the database so that the data can be quickly restored in the event of database problems or data loss. With the help of

How to restore dwg from bak file How to restore dwg from bak file Feb 20, 2024 am 09:44 AM

The bak file is a file format used in AutoCAD software to back up DWG files. When we accidentally delete or damage the original DWG file, we can use the bak file to restore it. This article will introduce how to restore dwg files using bak files. 1. Find the location of the bak file and the source DWG file. First, we need to find the location where the bak file and the source DWG file are stored. Normally, the bak file will be saved in the same folder as the DWG file. If you can't find it, you can try Win

See all articles