在 SharePoint Server 中連結或卸離內容資料庫Attach or detach content databases in SharePoint Server

摘要:了解如何連結與卸離內容資料庫與您的 SharePoint Server 2016 和 SharePoint 2013 伺服器陣列。Summary: Learn how to attach and detach content databases to your SharePoint 2013 farm.

要連結與卸離 SharePoint Server 內容資料庫,可使用 SharePoint 管理中心網站或 Microsoft PowerShellYou can attach or detach SharePoint 2013 content databases by using the SharePoint Central Administration website or Windows PowerShell 3.0

開始之前Before you begin

開始這項作業之前,請先檢閱下列資訊:Before you begin this operation, review the following information:

  • 若您要在附加時建立新內容資料庫,SharePoint 伺服器陣列服務帳戶必須為 SQL 伺服器 dbcreator 固定伺服器角色的成員。若要將內容資料庫附加至 Web 應用程式,SharePoint 伺服器陣列服務帳戶必須要有 db_owner 權限,才能使用內容資料庫。If you want to create a new content database while you attach it, the SharePoint farm service account must be a member of the SQL Server dbcreator fixed server role. To attach a content database to a web application, the SharePoint farm service account must have db_owner permission for the content database.

  • 若資料庫已經存在,則資料庫的版本必須與 SharePoint Server 2016 伺服器陣列相同,否則此操作將失敗。若要附加的內容資料庫版本與伺服器陣列不同,請使用下一節的使用 Windows PowerShell 附加與卸離內容資料庫程序操作。If the database already exists, it must be the same version as the SharePoint 2013 farm or this operation will fail. To attach a content database that is a different version than the farm, use the To attach or detach a content database by using Windows PowerShell procedure in the following section.

連結與卸離內容資料庫Attaching and detaching content databases

您可能會基於以下理由,附加或卸離內容資料庫。您需要新增新網站集合的新內容資料庫,以使內容資料庫保持可管理的大小。您需要從其他伺服器陣列恢復內容資料庫,並從 Web 應用程式存取內容資料庫內容的網站。您已從內容資料庫封存網站集合,然後從 Web 應用程式卸離內容資料庫。如需詳細資訊,請參閱<Move site collections between databases in SharePoint ServerYou might want to attach or detach content databases for the following reasons. You want to add a new content database for new site collections to keep content databases at a manageable size. You are restoring a content database from another farm and you want the sites that it contains to be accessed from a web application. You have archived site collections out of a content database and then detach the content database from the web application. For more information, see Move site collections between databases in SharePoint Server

新增資料庫與附加資料庫的步驟非常相似。如需如何新增資料庫的詳細資訊,請參閱<Add content databases in SharePoint Server>。The steps to add a database and to attach a database are very similar. For more information about how to add a database, see Add content databases in SharePoint Server.

使用「管理中心」連結內容資料庫To attach a content database by using Central Administration

  1. 確認要用來執行此作業的使用者帳戶為 SharePoint 伺服器陣列管理員群組成員。Verify that the user account that is being used to perform this operation is a member of the Farm Administrators SharePoint group.

  2. 啟動管理中心。Start Central Administration.

  3. 在 SharePoint 管理中心網站中,按一下 [應用程式管理]*On the SharePoint Central Administration website, click *Application Management.

  4. 在 [應用程式管理] 頁面的 [資料庫] 區域中,按一下 [管理內容資料庫]。On the Application Management page, in the Databases section, click Manage content databases.

  5. 在 [管理內容資料庫] 頁面中,按一下 [加入內容資料庫]。On the Manage Content Databases page, click Add a content database.

  6. 在 [新增內容資料庫]**** 頁面上,執行下列動作:On the Add Content Database page:

    • 使用 Web 應用程式下拉式功能表選取要附加內容資料庫的 Web 應用程式。Use the Web Application drop-down menu to select the web application to which you want to attach a content database.

    • 指定主控資料庫的資料庫伺服器。Specify the database server that hosts the database.

    • 指定資料庫名稱。如果資料庫不存在,則會建立一個。Specify the database name. If the database does not already exist, it will be created.

    • 指定資料庫的驗證方法,如果您使用的是 SQL 驗證,請提供帳戶名稱與密碼。Specify the authentication method for the database, and supply an account name and password if you are using SQL authentication.

      注意

      帳戶名稱與密碼必須是已經存在的 SQL Server 登入資訊。建議您使用 Windows 驗證,取代使用 SQL 驗證,SQL 驗證依預設會將非加密的密碼傳送到執行 SQL Server 的電腦。如果使用 SQL 驗證,則 SQL 帳戶需要具備與 SharePoint 伺服器陣列服務帳戶相同的 SQL 權限。The account name and password must already exist as a SQL Server login. We recommend that you use Windows authentication instead of SQL authentication because, by default, SQL authentication sends a nonencrypted password to the computer that is running SQL Server. If you use SQL authentication, the SQL account requires the same SQL permissions as the SharePoint farm service account.

  • 按一下 [確定]*Click *OK.

使用管理中心卸離內容資料庫To detach a content database by using Central Administration

  1. 確認執行此程序的使用者帳戶為 SharePoint 伺服器陣列管理員群組的成員。Verify that the user account that is performing this procedure is a member of the Farm Administrators SharePoint group.

  2. 在 SharePoint 管理中心網站中,按一下 [應用程式管理]。On the SharePoint Central Administration website, click Application Management.

  3. 在 [應用程式管理] 頁面的 [資料庫] 區段中,按一下 [管理內容資料庫]。On the Application Management page, in the Databases section, click Manage content databases.

  4. 選取要卸離內容資料庫的 Web 應用程式。Select the web application for which you want to detach a content database.

  5. 按一下要卸離的內容資料庫。Click the content database that you want to detach.

  6. 在 [管理內容資料庫設定] 頁面上,選取 [移除內容資料庫] 核取方塊。On the Manage Content Database Settings page, select the Remove content database check box.

    如果內容資料庫中包含資料,您將收到警告。按一下 [確定] 繼續執行作業。If the content database contains data, you will receive a warning. Click OK to continue with the operation.

  7. 按一下 [確定] 確認卸離作業,或按一下 [取消] 停止作業但不卸離資料庫。Click OK to confirm the detachment, or click Cancel to stop the operation without detaching the database.

    卸離管理中心中的內容資料庫後,內容資料庫仍會存在於 SQL Server。若您要永久移除內容資料庫,必須使用 SQL Server 程序操作。After detaching the content database in Central Administration, the content database still exists in SQL Server. If you want to permanently remove the content database, you must do so by using a SQL Server procedure.

使用 PowerShell 連結或卸離內容資料庫To attach or detach a content database by using Microsoft PowerShell

  1. 確認您具備下列成員身分:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 SharePoint Server Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint Server cmdlets.

      注意

      如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  2. 啟動 SharePoint 管理命令介面Open SharePoint Management Shell.

  3. 在 PowerShell 命令提示字元處,輸入適當命令At the Windows PowerShell command prompt, type the appropriate command

    若要連結現有的內容資料庫:To attach an existing content database:

    Mount-SPContentDatabase "<ContentDb>" -DatabaseServer "<DbServer>" -WebApplication http://SiteName
    

    其中:Where:

    • <內容資料庫> 是要附加的內容資料庫。<ContentDb> is the content database to be attached.

    • <DbServer> 是資料庫伺服器的名稱。<DbServer> is the name of the database server.

    • http://SiteName 是連結內容資料庫的 Web 應用程式名稱。http://SiteName is the name of the web application to which the content database is being attached.

      若要卸離內容資料庫:To detach a content database:

    Dismount-SPContentDatabase "<ContentdBName>"
    

    其中 <內容資料庫名稱> 是內容資料庫的名稱。Where <ContentdBName> is the name of the content database.

    重要

    如果您有多個內容資料庫具備相同的名稱,則在此命令中必須使用內容資料庫 GUID,而不能使用內容資料庫名稱。若要擷取內容資料庫的 GUID,請不要使用引數執行 Get-SPContentDatabase Cmdlet。If you have multiple content databases that have the same name, you must use the content database GUID in this command instead of using the content database name. To retrieve the GUID of the content database, run the Get-SPContentDatabase cmdlet with no arguments.

    Dismount-SPContentDatabase Cmdlet 會從 Web 應用程式中卸離內容資料庫,但是不會刪除 SQL Server 中的內容資料庫。卸離內容資料庫之後,您無法使用 PowerShell 將其刪除。您只能使用 SQL Server 工具刪除它。如果要在卸離內容資料庫時從 SQL Server 刪除它,請使用 Remove-SPContentDatabase Cmdlet。The Dismount-SPContentDatabase cmdlet detaches the content database from the web application, but it does not delete the content database from SQL Server. After a content database is detached, you cannot delete it by using Windows PowerShell 3.0. You can only remove it by using SQL Server tools. If you want to delete the content database from SQL Server while you detach it, use the Remove-SPContentDatabase cmdlet instead.

如需詳細資訊,請參閱<Dismount-SPContentDatabase>與<Mount-SPContentDatabase>。For more information, see Dismount-SPContentDatabase and Mount-SPContentDatabase.

注意

建議您在執行命令列管理工作時使用 Windows PowerShell。Stsadm 命令列工具已過時,但為與舊版產品相容,仍會隨附提供。We recommend that you use Microsoft PowerShell when performing command-line administrative tasks. The Stsadm command-line tool has been deprecated, but is included to support compatibility with previous product versions.

另請參閱See also

其他資源Other Resources

Get-SPContentDatabaseGet-SPContentDatabase

New-SPContentDatabaseNew-SPContentDatabase

Remove-SPContentDatabaseRemove-SPContentDatabase