适用于 Azure SQL 数据库和 SQL 托管实例的 Azure CLI 示例Azure CLI samples for Azure SQL Database and SQL Managed Instance

适用于: Azure SQL 数据库 Azure SQL 托管实例

可以使用 Azure CLI 来配置 Azure SQL 数据库和 SQL 托管实例。You can configure Azure SQL Database and SQL Managed Instance by using the Azure CLI.

如果没有 Azure 试用版订阅,请在开始前创建一个试用版订阅If you don't have an Azure trail subscription, create a trial subscription before you begin.

先决条件Prerequisites

  • 如果需要,请安装 Azure CLI 来运行 CLI 参考命令。If you prefer, install the Azure CLI to run CLI reference commands.

    • 如果使用的是本地安装,请使用 az login 命令登录到 Azure CLI。If you're using a local installation, sign in to the Azure CLI by using the az login command. 若要完成身份验证过程,请遵循终端中显示的步骤。To finish the authentication process, follow the steps displayed in your terminal. 有关其他登录选项,请参阅登录 Azure CLIFor additional sign-in options, see Sign in with the Azure CLI.

    • 出现提示时,请在首次使用时安装 Azure CLI 扩展。When you're prompted, install Azure CLI extensions on first use. 有关扩展详细信息,请参阅使用 Azure CLI 的扩展For more information about extensions, see Use extensions with the Azure CLI.

    • 运行 az version 以查找安装的版本和依赖库。Run az version to find the version and dependent libraries that are installed. 若要升级到最新版本,请运行 az upgradeTo upgrade to the latest version, run az upgrade.

  • 本教程需要 Azure CLI 版本 2.0 或更高版本。This tutorial requires version 2.0 or later of the Azure CLI.

下表包括一个链接,该链接指向用于管理 Azure SQL 数据库中的单个和共用数据库的 Azure CLI 脚本示例。The following table includes links to Azure CLI script examples to manage single and pooled databases in Azure SQL Database.

领域Area 说明Description
在 Azure SQL 数据库中创建数据库Create databases in Azure SQL Database
创建单一数据库和配置防火墙规则Create a single database and configure a firewall rule 创建 SQL 数据库并配置服务器级防火墙规则。Creates an SQL Database and configures a server-level firewall rule.
创建弹性池并移动共用数据库Create elastic pools and move pooled databases 创建弹性池、移动共用数据库,并更改计算大小。Creates elastic pools, moves pooled databases, and changes compute sizes.
在 Azure SQL 数据库中缩放数据库Scale databases in Azure SQL Database
缩放单一数据库Scale a single database 先查询 SQL 数据库中某个数据库的大小信息,然后将该数据库缩放到不同的计算大小。Scales a database in SQL Database to a different compute size after querying the size information for the database.
缩放弹性池Scale an elastic pool 将 SQL 弹性池缩放为不同的计算大小。Scales a SQL elastic pool to a different compute size.
配置异地复制和故障转移Configure geo-replication and failover
将单一数据库添加到故障转移组Add a single database to a failover group 创建一个数据库和一个故障转移组,将此数据库添加到该故障转移组,然后测试到辅助服务器的故障转移。Creates a database and a failover group, adds the database to the failover group, then tests failover to the secondary server.
为弹性池配置故障转移组Configure a failover group for an elastic pool 创建一个数据库,将其添加到弹性池,将弹性池添加到故障转移组,然后测试到辅助服务器的故障转移。Creates a database, adds it to an elastic pool, adds the elastic pool to the failover group, then tests failover to the secondary server.
使用活动异地复制配置单一数据库并对其进行故障转移Configure and fail over a single database by using active geo-replication 为 Azure SQL 数据库中的数据库配置活动异地复制,并将其故障转移到次要副本。Configures active geo-replication for a database in Azure SQL Database and fails it over to the secondary replica.
使用活动异地复制配置共用数据库并对其进行故障转移Configure and fail over a pooled database by using active geo-replication 为弹性池中的数据库配置活动异地复制,然后将其故障转移到次要副本。Configures active geo-replication for a database in an elastic pool, then fails it over to the secondary replica.
审核和威胁检测Auditing and threat detection
配置审核和威胁检测Configure auditing and threat-detection 为 Azure SQL 数据库中的数据库配置审核和威胁检测策略。Configures auditing and threat detection policies for a database in Azure SQL Database.
备份、还原、复制和导入数据库Back up, restore, copy, and import a database
备份数据库Back up a database 将 SQL 数据库中的数据库备份到 Azure 存储备份。Backs up a database in SQL Database to an Azure storage backup.
还原数据库Restore a database 从异地冗余备份中还原 SQL 数据库中的数据库,并将已删除的数据库还原到最新备份。Restores a database in SQL Database from a geo-redundant backup and restores a deleted database to the latest backup.
将数据库复制到新服务器Copy a database to a new server 在新服务器中创建 SQL 数据库中某个现有数据库的副本。Creates a copy of an existing database in SQL Database in a new server.
从 BACPAC 文件导入数据库Import a database from a BACPAC file 将数据库从 BACPAC 文件导入到 SQL 数据库。Imports a database to SQL Database from a BACPAC file.

详细了解单一数据库 Azure CLI APILearn more about the single-database Azure CLI API.