1. 实例恢复在实例重新启动时,系统自动恢复。判断依据:数据文件的scn与控制文件不一致。步骤:(1)使用online redo log,数据前
1. 实例恢复
在实例重新启动时,系统自动恢复。
判断依据:数据文件的scn与控制文件不一致。
步骤:
(1)使用online redo log,数据前滚到与控制文件一致的SCN处。
(2)使用undo表空间,对未提交事务执行回滚操作。
结果:数据库中数据保留到实例异常前最后一次提交的内容。
2. 用户错误恢复
用户错误包括:用户数据错误修改,数据表误删等
恢复技术:闪回查询(Flashback Query)
Flashback Drop和表空间回收站(Tablespace's recycle bin)
闪回表(Flashback Table)
LogMiner
2.1 闪回查询
前提:undo表空间足够容纳用户在一段时期内修改的数据
undo表空间保留历史修改数据的时限(UNDO_RETETION初始变量)
查询表employees在15分钟前的数据:
SELECT employee_id, last_name, email FROM hr.employees
AS OF TIMESTAMP(systimestamp - interval '15' minute)
WHERE employee_id = 101;
查询表employees在指定历史时间的数据:
SELECT employee_id, last_name, email FROM hr.employees
AS OF TIMESTAMP(
to_timestamp('01-Sep-04 16:18:57.84', 'DD-Mon-RR HH24:MI:SS.FF'))
WHERE employee_id = 101;
2.2 Flashback Drop和表空间回收站
每个Oracle表空间中存在一个Recycle bin,用户存放删除的表和表相关内容(索引等)
删除的表所占用的空间并不立即回收,但在视图DBA_FREE_SPACE中可看到。
# 恢复已删除的数据表到删除前状态(包括表中数据):
SQL> FLASHBACK TABLE order_items TO BEFORE DROP;
# 恢复已删除的数据表并改名:
SQL> FLASHBACK TABLE order_items TO BEFORE DROP RENAME TO order_items_old;
如果同一个表被删除恢复多次,如果需要恢复到以前的版本,则可以查询视图RECYCLEBIN
或者使用命令SHOW RECYCLEBIN,并使用其中的表名称。
使用限制:
仅能用于非系统本地管理的表空间。
位图联合索引、参照完整性约束、物化视图删除后无法保存在Recyclebin.
使用Drop Index删除索引,删除的索引不会保存(只有删除表,,县官索引才保存)。
2.3 Flashback表
允许将一个或多个表恢复到历史指定时间的状态。无需使用太耗时的操作。
Flashback Table使用对相关事务的Undo操作恢复表,使用undo表空间。
(Flashback Drop直接回收恢复表占用的空间)
需要启用行迁移(row movement)功能。undo操作可能会改变记录的rowid.
#启用Row Movement
SQL> ALTER TABLE hr.employees ENABLE ROW MOVEMENT;
#使用Flashback Table恢复表到指定时间
SQL> FLASHBACK TABLE hr.employees [, ...]
TO TIMESTAMP systimestamp - interval '15' minute;
2.4 LogMiner
从Redo Log中提取所有的DDL和DML活动的语句。
使用V$LOGMNR_CONTENTS视图查看(首先需要执行DBMS_LOGMNR.START_LOGMNR()过程)
LogMiner工具本身不能用于恢复数据库
仅从RedoLog中提取用于恢复数据库的SQL语句。
3. 控制文件恢复
如果有控制文件发生错误,Oracle实例将停止运行。
如果没有停止,则必须手动执行:SHUTDOWN ABORT
将未损坏的控制文件复制一份到目标地址,并修改初始化参数中出问题的
控制文件的路径到新的控制文件
或者在初始化参数中把有问题的控制文件条目删除。
控制文件错误时,修改初始化参数参数,需要在NOMOUNT状态下。
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP NOMOUNT;
SQL> SHOW PARAMETER CONTROL_FILES;
或
SQL> SELECT name, value FROM v$spparameters
WHERE name = 'control_files';
SQL> ALTER SYSTEM SET CONTROL_FILES='...','...','...' SCOPE=SPFILE;
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP;
4. 重做日志恢复
只要有一组中还有一个Redo Log文件还有可用,Oracle实例就不会崩溃。
(即一个redo log组中所有redo log文件全部失效,Oracle示例就会崩溃)
使用V$LOGFILE视图查询当前redo log文件的状态。
如果一个redo log组中存在错误的redo log文件,那么按以下步骤恢复:
# 确认哪个文件出现错误(在哪个组中)
SQL> SELECT * FROM v$logfile ORDER BY group#;
# 对该组redo log执行归档操作
SQL> ALTER SYSTEM ARCHIVE LOG GROUP
# 清空有问题的redo log组并重建
SQL> ALTER DATABASE CLEAR LOGFILE GROUP
5. 系统关键数据文件恢复
包括SYSTEM表空间和UNDO表空间。
5.1 NOARCHIVELOG 模式下
只能依赖于是否对数据库有全备份,如果有,则只能恢复到全备份时。
5.2 ARCHIVELOG 模式下
SQL> SHUTDOWN ABORT; # 强制停止
SQL> STARTUP MOUNT; # 只能在Mount状态下恢复
在EM的Perform Recovery中,选择恢复数据文件,以及对应的SYSTEM表空间数据文件。
并可指定需要恢复到的目标路径。系统将会执行RMAN脚本进行恢复。
SQL> ALTER DATABASE OPEN; # 恢复完毕后打开数据库
6. 非系统数据文件恢复
6.1 NOARCHIVELOG 模式下
只能依赖于是否对数据库有全备份,如果有,则只能恢复到全备份时。
6.2 ARCHIVELOG 模式下
只影响到丢失的数据文件相关的数据库对象。
同样可在EM中,按步骤执行Perform Recovery进行恢复。
# 查看数据文件
SQL> SELECT t.name, d.name FROM v$tablespace t
JOIN v$datafile d USING (ts#)
WHERE t.name = 'USERS';
也可以执行RMAN命令恢复编号为4和7的数据文件:
$ rman target /
RMAN> run { sql 'alter database datafile 4 offline';
sql 'alter database datafile 7 offline';
restore datafile 4, 7;
recover datafile 4, 7;
sql 'alter database datafile 4 online';
sql 'alter database datafile 7 online'; }

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi


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

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
