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)

Hot Topics

Java Tutorial
1663
14
PHP Tutorial
1263
29
C# Tutorial
1237
24
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.

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

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

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

PHP and Memcached database backup and recovery PHP and Memcached database backup and recovery May 15, 2023 pm 09:12 PM

With the rapid development of the Internet, large-scale MySQL database backup and recovery has become one of the essential skills for major enterprises and websites. With the widespread application of Memcached, how to back up and restore Memcached has also become an important issue. As one of the main languages ​​for web development, PHP has unique advantages and skills in handling backup and recovery of MySQL and Memcached. This article will introduce in detail the implementation method of PHP processing MySQL and Memcached backup and recovery.

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

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 the one-click restore function to restore the black screen problem in Windows 10 system How to use the one-click restore function to restore the black screen problem in Windows 10 system Jan 15, 2024 pm 04:54 PM

When we use the computer, if we encounter frequent black screens, we may think of using the one-click restore function that comes with the system, which is to restore the damaged and problematic system to the time of our backup. So as far as the editor knows, we can find updates and security in the system settings and then perform a series of operations. Let’s take a look at the specific steps to see how the editor did it~ How to restore the black screen of Windows 10 system with one click Method 1: System recovery 1. After turning on the computer, when you see the Windows 10 Logo and there is a circle below it, count 5 seconds. Then directly press the power button to shut down. For desktop computers, if there is a "reset button" on the chassis, you can also press the restart button directly. 2. Repeat 2~

See all articles