mysql,sqlsever,oracle,redis,mongo,postgres等数据库备份及恢复指令整理_MySQL
下列仅整理给出各个数据库备份及恢复最简单的用法,更多详细的参数及配置请查阅相关资料
一、mysql:
参数说明:
$user | $password | $targethost | $port | $charset | $dbname | $table | $filename |
用户名 | 密码 | ip(本地为localhost) | 端口 | 编码 | 数据库名 | 表名(仅表级备份需要) | 文件名 |
备份:mysqldump --single-transaction -l -u $user -p'$password' -h $targethost -P $port --default-character-set=$charset $dbname $table > $filename
恢复:mysql $dbname -u $user -p'$password' -h $targethost -P $port --default-character-set=$charset
二、sqlserver:
说明:sqlserver2003及以下仅支持osql,sqlserver2005及以上同时支持osql及sqlcmd,以下方法对sqlcmd及osql均通用。
参数说明:
$user | $passwrod | $instance | $dbname | $filename | $diff_filename |
用户名 | 密码 | 实例名 | 数据库名 | 全量备份文件名 | 增量备份文件名 |
全量备份:osql -U $user -P "$password" -d master -S $instance -Q "ALTER DATABASE $dbname SET OFFLINE WITH ROLLBACK IMMEDIATE; RESTORE DATABASE $dbname FROM DISK='$filename' WITH REPLACE; ALTER DATABASE $dbname SET ONLINE"
增量备份:osql -U $user -P "$password" -d master -S $instance -Q "ALTER DATABASE $dbname SET OFFLINE WITH ROLLBACK IMMEDIATE; RESTORE DATABASE $dbname FROM DISK='$filename' WITH REPLACE,NORECOVERY; RESTORE DATABASE $dbname FROM DISK='$diff_filename' WITH RECOVERY; ALTER DATABASE $dbname SET ONLINE"
全量恢复:osql -U $user -P "$password" -d master -S $instance -Q "ALTER DATABASE $dbname SET OFFLINE WITH ROLLBACK IMMEDIATE; RESTORE DATABASE $dbname FROM DISK='$filename' WITH REPLACE; ALTER DATABASE $dbname SET ONLINE"
增量恢复:osql -U $user -P "$password" -d master -S $instance -Q "ALTER DATABASE $dbname SET OFFLINE WITH ROLLBACK IMMEDIATE; RESTORE DATABASE $dbname FROM DISK='$filename' WITH REPLACE,NORECOVERY; RESTORE DATABASE $dbname FROM DIST='$diff_filename' WITH RECOVERY; ALTER DATABASE $dbname SET ONLINE"
三、oracle:
oracle的备份及恢复主要使用rman,感兴趣的可以详细去了解rman的具体使用
四、redis:
说明:redis的数据备份文件存储在配置文件中的dir+dbfilename组成的全路径文件名中;
备份:redis-cli -h targethost -p $port -a $password save
恢复:只需要将备份的文件放置原目录,重启redis即可。
五、mongo:
参数说明:
$targethost | $port | $dbname | $backup_dir | $user | $password | $table | $recovery_dir |
ip地址 | 端口 | 数据库名 | 保存路径 | 用户名 | 密码 | 表名(表级恢复) | 恢复路径 |
备份:mongodump --host $targethost:$port -d $dbname -o $backup_dir -u $user -p $password
恢复:mongorestore --host $targethost:$port -d $dbname -u $user -p$password -c $table $recovery_dir
六、postgres:
$targethost | $port | $user | $dbname | $filename | $recovery_file |
ip地址 | 端 口 | 用户名 | 数据库名 | 备份文件 | 恢复文件 |
备份:pg_dump -c -b -h $targethost -p $port -U "$user" $dbname > $filename
恢复:psql -h $targethost -p $port -U "$user" -d $dbname -f $recovery_file

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics





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.

Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

PHP is a back-end programming language widely used in website development. It has powerful database operation functions and is often used to interact with databases such as MySQL. However, due to the complexity of Chinese character encoding, problems often arise when dealing with Chinese garbled characters in the database. This article will introduce the skills and practices of PHP in handling Chinese garbled characters in databases, including common causes of garbled characters, solutions and specific code examples. Common reasons for garbled characters are incorrect database character set settings: the correct character set needs to be selected when creating the database, such as utf8 or u
