Home Database Mysql Tutorial 使用nid命令修改 db name 及 dbid

使用nid命令修改 db name 及 dbid

Jun 07, 2016 pm 05:28 PM

工作中不可避免地碰到需要修改dbname以及dbid的情形,如将数据库恢复到同一台机器的情形是其中之一。但dbname以及dbid是用于标识

工作中不可避免地碰到需要修改dbname以及dbid的情形,如将数据库恢复到同一台机器的情形是其中之一。但dbname以及dbid是用于标识数据库的重要标志之一,尤其是dbid,具有唯一性,因此对其修改应慎重处理。本文描述了修改dbname以及dbid的步骤并给出示例。

1、修改dbid及dbname的影响

a、修改dbid

等同于创建一个新的数据库,不同的是数据已经存在于数据文件。这是由dbid的唯一性决定的。

修改之后所有之前的备份与归档日志将不可用,因为在恢复时会检测dbid,由于不匹配,则所有备份无效。

修改之后需要使用open resetlogs打开数据库,一个新的incarnation会被创建,且sequence被置为1。

修改之后且成功open的情形下,建议一致性关闭数据库,重启并做一个完整的备份。

b、修改dbname

修改之后,无需使用open resetlogs打开数据库。(注dbname不具有唯一性,global name则具有唯一性)。

修改之后,所有的备份即归档日志依旧可用。

修改之后,,需要修改pfile/spfile中对应的db_name参数以及重建相应的Oracle密码文件。

如果需要使用旧的控制文件恢复数据库,应当使用修改之前的pfile/spfile以及密码文件启动数据库再进行恢复。

c、同时修改dbid及dbname

如果同时修改,则是上述两种情形的综合,修改完毕后需要open resetlogs以及修改pfile/spifle,密码文件,全备数据库。

2、nid命令

robin@SZDB:~> nid

DBNEWID: Release 10.2.0.3.0 - Production on Thu Apr 24 16:34:28 2013

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Keyword    Description                    (Default)

----------------------------------------------------

TARGET      Username/Password              (NONE)

DBNAME      New database name              (NONE)

LOGFILE    Output Log                    (NONE)

REVERT      Revert failed change          NO

SETNAME    Set a new database name only  NO

APPEND      Append to output log          NO

HELP        Displays these messages        NO

在执行nid命令时,该程序会校验当前数据库所有数据文件以及控制文件的头部信息,校验成功后提示是否要修改。

如果使用了输出到日志文件logfile则不会出现修改提示。

接下来nid将使用新的dbid(或者dbname)逐个修改控制文件,数据文件(包括只读文件,正常脱机文件)的头部。

修改成功后自动关闭数据库并退出。

注:对于只读文件,正常脱机文件本文未作测试。其次应确保数据库处于归档状态,可正常归档以及不存在需要recover的数据文件。

3、修改步骤

a、全备数据库,如果是热备(rman or os)应确保所有的归档日志以及联机日志可用

b、删除dbconsole([ID 863800.1]有此要求,如用到dbconsole,应考虑按此操作)

c、启动需要修改的数据库到mount状态(startup mount)

d、如果使用spfile文件启动数据库,备份spfile文件到pfile用于后续修改db_name

e、发布nid命令

nid target=sys/password                                  #此方式是仅仅修改dbid

nid target=/ dbname=new_dbname [setname=yes]            # / 表明连接到当前环境的sid,且使用操作系统认证

nid target=sys/password dbname=new_dbname [setname=yes]  # setname=yes 仅仅修改数据库名字,如果省略,则两者同时修改

nid target=sys/pwdd@conn_string dbname=new_dbname [setname=yes] #使用连接串连接到远程主机并修改

f、修改Oracle 参数文件 pfile(使用先前从spfile备份的)中的参数db_name,如果仅仅修改dbid,跳过此步骤

g、使用新的参数文件pfile启动到mount状态(如果修改了dbname,如果仅仅是dbid,则直接使用原来的pfile或spfile启动)

h、使用open resetlogs方式打开数据库(修改非dbid,直接打开即可)

i、重建当前数据库的 Oralce 密码文件及将pfile文件转换成spfile文件

j、修改相应的监听器的配值,包括listener.ora以及tnsnames.ora

k、修改全局dbname,如果有用到的话。ALTER DATABASE RENAME GLOBAL_NAME TO .;

l、重建dbconsole      $ emca -config dbcontrol db -repos recreate

m、全备数据库

linux

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

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 do you alter a table in MySQL using the ALTER TABLE statement? How do you alter a table in MySQL using the ALTER TABLE statement? Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Explain InnoDB Full-Text Search capabilities. Explain InnoDB Full-Text Search capabilities. Apr 02, 2025 pm 06:09 PM

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

How do I configure SSL/TLS encryption for MySQL connections? How do I configure SSL/TLS encryption for MySQL connections? Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

How do you handle large datasets in MySQL? How do you handle large datasets in MySQL? Mar 21, 2025 pm 12:15 PM

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Difference between clustered index and non-clustered index (secondary index) in InnoDB. Difference between clustered index and non-clustered index (secondary index) in InnoDB. Apr 02, 2025 pm 06:25 PM

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values ​​and pointers to data rows, and is suitable for non-primary key column queries.

Can I install mysql on Windows 7 Can I install mysql on Windows 7 Apr 08, 2025 pm 03:21 PM

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

See all articles