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

适用于:是 Azure SQL 数据库 是Azure SQL 托管实例 APPLIES TO: yesAzure SQL Database yesAzure SQL Managed Instance

可以使用 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 subscription, create a trial account before you begin.

可以在本地安装并使用 CLI,本主题要求运行 Azure CLI 2.0 或更高版本。You can install and use the CLI locally, this topic requires that you are running the Azure CLI version 2.0 or later. 运行 az --version 即可查找版本。Run az --version to find the version. 如需进行安装或升级,请参阅安装 Azure CLIIf you need to install or upgrade, see Install 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.

在 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.