azure云数据库_如何使用Cloud Shell创建Azure SQL数据库

azure云数据库

介绍 (Introduction)

Cloud Shell is a new feature just released on May 2017. It is currently in beta.

Cloud Shell是2017年5月刚刚发布的一项新功能。它目前处于测试阶段。

The idea behind the Cloud Shell is to run Azure commands using the Azure Portal directly. In the past, it was necessary to install the Azure CLI on a local machine. You could install on a Windows, Linux or a Mac machine or you could use Docker. Now, you can use the Azure Portal.

Cloud Shell背后的想法是直接使用Azure门户运行Azure命令。 过去,有必要在本地计算机上安装Azure CLI 。 您可以安装在Windows,Linux或Mac机器上,也可以使用Docker。 现在,您可以使用Azure门户。

In this article, we are going to create an Azure SQL Server and an Azure SQL Database inside the server using the Cloud Shell. Specifically, we are going to use bash in Azure.

在本文中,我们将使用Cloud Shell在服务器内部创建Azure SQL Server和Azure SQL数据库。 具体来说,我们将在Azure中使用bash。

要求 (Requirements)

  1. A subscription to Azure 订阅Azure

开始吧 (Get started)

To start, in the Azure Portal, you will be able to see the new icon >_. This icon will be used to enter to the Cloud Shell:

首先,在Azure门户中,您将能够看到新图标> _。 此图标将用于输入Cloud Shell:


You will receive a message to create a storage to persist your $Home directory:

您将收到一条消息,用于创建存储以保留$ Home目录:


When you select the option, the storage account will be created. Also, a resource group and a File Share are created.

选择该选项后,将创建存储帐户。 此外,将创建资源组和文件共享。

To verify, in the Azure Portal, press the > icon and select Storage accounts:

若要进行验证,请在Azure门户中按>图标,然后选择“ 存储帐户”


When we created a storage account a resource group named cloud-shell-storage-eastus was created and a storage named cs2994fc6e1ea72x40edx8df:

创建存储帐户时,创建了一个名为cloud-shell-storage-eastus的资源组,并创建了一个名为cs2994fc6e1ea72x40edx8df的存储:



Inside the storage account, we created a File share. To verify it, click on the storage and go to Files:

在存储帐户中,我们创建了文件共享。 要验证它,请单击存储并转到文件:



You will see a File service created. In our example, the File service name is cs-10037ffe8ccf1801 of 6 GiB. Click on it:

您将看到创建了文件服务。 在我们的示例中,文件服务名称是6 GiB的cs-10037ffe8ccf1801 。 点击它:



If you press Connect you can create a file share to Windows. This is very useful to copy files from your local Windows machine to Azure or vice versa:

如果按“ 连接” ,则可以创建Windows的文件共享。 这对于将文件从本地Windows计算机复制到Azure或反之亦然非常有用:



In the command line (cmd), copy the command, but assign a drive letter like this:

在命令行(cmd)中,复制命令,但分配一个驱动器号,如下所示:

net use z: \\cs2994fc6e1ea72x40edx8df.file.core.windows.net\cs-10037ffe8ccf1801 /u:AZURE\cs2994fc6e1ea72x40e

净使用z:\\ cs2994fc6e1ea72x40edx8df.file.core.windows.net \ cs-10037ffe8ccf1801 / u:AZURE \ cs2994fc6e1ea72x40e

On your local machine, you will see that the new drive was created. You can copy and paste files there:

在本地计算机上,您将看到新驱动器已创建。 您可以在此处复制和粘贴文件:


Return to the Cloud Shell that was activated in Figure 1. You will connect to Bash.

返回到图1中激活的Cloud Shell。您将连接到Bash。

Bash is a popular shell in Unix and Linux and now you can use it on Azure. If you are a Windows User, we can say that it is more powerful than the cmd and similar to PowerShell:

Bash是Unix和Linux中流行的shell,现在您可以在Azure上使用它。 如果您是Windows用户,我们可以说它比cmd更强大,并且类似于PowerShell:


As you can see, PowerShell is not supported yet in the Cloud Shell yet, but it will be supported soon:

如您所见,Cloud Shell尚不支持PowerShell,但很快将支持它:


The first command that we will try is the help. It will show you soome links to a Microsoft web site with basic information about Cloud Shell:

我们将尝试的第一个命令是帮助。 它将向您显示指向Microsoft网站的链接,其中包含有关Cloud Shell的基本信息



Az help is another command that will list the different commands in bash for Azure:

Az help是另一个命令,它将在bash中列出Azure的不同命令:


The command az –version, displays the version of the different Azure Cli components:

命令az –version ,显示不同的Azure Cli组件的版本:


创建Azure SQL数据库 (Creating an Azure SQL Database)

To create an Azure SQL Database, it is necessary to create:

若要创建Azure SQL数据库,必须创建:

  • An Azure Group

    Azure组
  • An Azure SQL Server

    Azure SQL服务器

First, we are going to create an Azure group named mysqlshackgroup. The parameter –l is used to specify the location (like eastus, northeurope, eastasia and more) and –n is used to specify the name:

首先,我们将创建一个名为mysqlshackgroup的Azure组。 参数–l用于指定位置(例如eastus,northeurope,eastasia等),而–n用于指定名称:

Az group create –l southcentralus –n mysqlshackgroup

Az组create –l southcentralus –n mysqlshackgroup


Note that the results are displayed in JSON format.

请注意,结果以JSON格式显示。

In the next example, we are going to create a server named shackserver it will be created in the group mysqlshackgroup just created above. The parameter –s is to specify the server name, -u is to specify the user name (in this example the user name is admin) and the password uses the parameter –p.

在下一个示例中,我们将创建一个名为shackserver的服务器,它将在上面刚刚创建的mysqlshackgroup组中创建。 参数–s用于指定服务器名称,-u参数用于指定用户名(在本示例中,用户名为admin),密码使用参数–p。

The location is southcentralus and it uses the –l parameter:

该位置是southcentralus,它使用–l参数:



To verify in the Portal, you can click on the > icon and in the search text box write sql server and click on the SQL servers icon:

要在门户中进行验证,可以单击>图标,然后在搜索文本框中编写sql server ,然后单击SQL server图标:


You will be able to see the database created:

您将能够看到创建的数据库:



To verify that the Azure SQL Server was create you can use the az sql server list command.

若要验证是否已创建Azure SQL Server,可以使用az sql server list命令。

You only need to specify the Azure Resource Group and it will show all the SQL Servers in the group:

您只需要指定Azure资源组,它将显示该组中的所有SQL Server:

az sql server list –g mysqlshackgroup

az sql服务器列表–g mysqlshackgroup



Note that the session can be idle for 10 minutes after that it is disconnected and you need to reconnect the console by pressing Enter:

请注意,会话在断开连接后可以空闲10分钟,您需要按Enter重新连接控制台:



To create the database, you need to specify the name of the database (in this example newsqlshackdb), the Azure server name (shackserver) and the Azure Resource group (mysqlshackgroup):

若要创建数据库,需要指定数据库名称(在本示例中为newsqlshackdb),Azure服务器名称(shackserver)和Azure资源组(mysqlshackgroup):

az sql create –n newsqlshackdb –s shackserver –g mysqlshackgroup

az sql create –n newsqlshackdb –s shackserver –g mysqlshackgroup


If you check the maxSizeBytes parameter, it has 268435456000 bytes (250 Gb), you can verify that the Database was created in the portal if you click on the SQL icon:

如果检查maxSizeBytes参数,该参数具有268435456000字节(250 Gb),则可以通过单击SQL图标来验证数据库是在门户中创建的:


The minimum size allowed is 100 MB. To reduce the size, you can update the Azure SQL Properties. The following commands will change the maximum database size to 100 MB:

允许的最小大小为100 MB。 若要减小大小,可以更新Azure SQL属性。 以下命令会将最大数据库大小更改为100 MB:

az sql db update -n newsqlshackdb -s shackserver -g mysqlshackgroup –max-size 100MB

az sql数据库更新-n newsqlshackdb -s shackserver -g mysqlshackgroup –最大大小100MB

In the Azure Portal, you can go to databases and check the MAX SIZE in the properties section. As you can see, it was successfully changed to 100 MB:

在Azure门户中,可以转到数据库并在“属性”部分中检查“最大大小”。 如您所见,它已成功更改为100 MB:



You can verify the database properties of the databases in the group mysqlshackgroup by using the az sql db list:

您可以使用az sql db列表来验证mysqlshackgroup组中数据库的数据库属性:

az sql db list -s shackserver -g mysqlshackgroup

az sql数据库列表-s shackserver -g mysqlshackgroup

There are two databases, the master database, which is a system database not visible in the Portal UI and the new sqlshackdb.

有两个数据库,一个是master数据库,一个是在Portal UI中不可见的系统数据库,另一个是新的sqlshackdb。



The property maxSizeBytes shows the maximum size of the database in bytes. The Maximum Size is 100 MB:

maxSizeBytes属性显示数据库的最大大小(以字节为单位)。 最大大小为100 MB:


结论 (Conclusions)

Cloud Shell is a new feature that helps to run the command line without installing new software in the local machine. It is very useful and it creates a Storage Account with a file share that allows to copy and paste local files from and to Azure easily. At the moment, Bash is available, but soon we will be able to run PowerShell in the Cloud directly and automate the tasks easily.

Cloud Shell是一项新功能,可帮助您运行命令行而无需在本地计算机上安装新软件。 它非常有用,它创建了一个具有文件共享的存储帐户,该帐户允许轻松地在Azure中复制和粘贴本地文件。 目前,Bash可用,但是不久我们将能够直接在云中运行PowerShell并轻松地自动执行任务。

Other articles in this series:

本系列的其他文章:

翻译自: https://www.sqlshack.com/how-to-create-an-azure-sql-database-using-the-cloud-shell/

azure云数据库

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值