赞
踩
azure云数据库
Today, it is a common practice to migrate our local data to Azure. Sometimes, we migrate files, sometimes databases and sometimes virtual machines. All the service in the cloud including Azure help a lot to simplify the administrative effort and reduce costs.
如今,将本地数据迁移到Azure是一种常见的做法。 有时,我们迁移文件,有时是数据库,有时是虚拟机。 云中的所有服务(包括Azure)都可以极大地帮助简化管理工作并降低成本。
This time, we will teach how to export tables from MySQL to Azure SQL database. This article is oriented to professionals with experience in MySQL, but new in the Azure world. We will use the SSMA from MySQL first and then we will learn how to migrate data with SQL Server Integration Services.
这次,我们将教如何将表从MySQL导出到Azure SQL数据库。 本文面向具有MySQL经验的专业人士,但在Azure世界中却是新手。 我们将首先使用MySQL的SSMA,然后将学习如何使用SQL Server Integration Services迁移数据。
Azure SQL database is a very simple Microsoft database stored in the cloud. It is similar to SQL Server, but it is simpler to install, create and maintain. In this example, we will create a blank database from 0 in less than 5 minutes and then we will migrate the data.
Azure SQL数据库是存储在云中的非常简单的Microsoft数据库。 它与SQL Server类似,但安装,创建和维护更简单。 在此示例中,我们将在不到5分钟的时间内从0创建一个空白数据库,然后迁移数据。
We will first create an Azure SQL Database (ASD). We will require an Azure SQL database Server, which can be created during the database creation. In the Azure Portal, click the SQL Database icon and then press the +Add icon:
我们将首先创建一个Azure SQL数据库(ASD)。 我们将需要可以在数据库创建期间创建的Azure SQL数据库服务器。 在Azure门户中 ,单击“ SQL数据库”图标,然后按+ Add图标:
Enter the database name. The subscription is usually one and is selected by default. This option is important if you have multiple subscription, which is not common is you are just starting with Azure.
输入数据库名称。 订阅通常是一个,默认情况下处于选中状态。 如果您有多个订阅,则此选项很重要,这并不常见,因为您只是从Azure开始。
A Resource Group is used to group and administer different Azure Resources. If it is your first time in Azure, Create a new group. Select source allows creating a sample database with some tables with data already created. In this example, we will create a Blank database, because we only want to load the data from MySQL to Azure.
资源组用于对不同的Azure资源进行分组和管理。 如果这是您第一次使用Azure,请创建一个新组。 选择源允许使用包含已创建数据的某些表来创建示例数据库。 在此示例中,我们将创建一个Blank数据库,因为我们只想将数据从MySQL加载到Azure。
Server is used to create a New server or an existing one. If it is your first time in Azure and you do not have an Azure SQL database Server (ASS), create a new server. You will need to specify a login and a password. The location is used to specify the region where you want to store the information. Use the region closer to the persons that are going to use the database. If people from different regions are going to use the data, it is possible to replicate the database in multiple regions using geo-replication, but the secondary database is read-only.
服务器用于创建新服务器或现有服务器。 如果这是您第一次使用Azure,并且没有Azure SQL数据库服务器(ASS),请创建一个新服务器。 您将需要指定登录名和密码。 该位置用于指定您要存储信息的区域。 使用离要使用数据库的人员更近的区域。 如果来自不同地区的人们将要使用数据,则可以使用geo-replication在多个区域中复制数据库,但是辅助数据库是只读的。
The Pricing tier is very important, because it is the price of the server. In Azure, you pay based on storage and the number of DTUs (a measure for performance) supported. The most expensive option is the Premium option; the maximum value configurable by the moment is 16,000 USD approx. per month. It supports 1 TB and 4000 DTUs:
定价层非常重要,因为这是服务器的价格。 在Azure中,您根据存储和支持的DTU数量(性能度量)进行支付。 最昂贵的选择是高级选项。 目前可配置的最大值约为16,000 USD。 每月。 它支持1 TB和4000 DTU:
In this example, we are going to use the Basic option. It supports 5 DTUs and 100 MB of storage. The cost is 5 USD approx. per month:
在此示例中,我们将使用“ 基本”选项。 它支持5个DTU和100 MB的存储空间。 费用约为5美元。 每月:
Once that you have all the information, press the Create button:
获得所有信息后,请按“ 创建”按钮:
If you go to SQL databases again, the database created will be displayed:
如果再次转到SQL数据库,将显示创建的数据库:
As you can see, creating a database is very simple. If you click the database and go to overview, you can see the Server name. This server name is very important and we will use later to connect to Azure:
如您所见,创建数据库非常简单。 如果单击数据库并转到概述,则可以看到服务器名称。 此服务器名称非常重要,稍后我们将使用它来连接到Azure:
We will need to open a firewall rule to connect in our local machine to our Azure SQL Database. To do it, in the Portal, press the > icon and select SQL servers:
我们将需要打开防火墙规则以将我们的本地计算机连接到我们的Azure SQL数据库。 为此,请在门户网站中按>图标,然后选择SQL服务器:
Select the database and click on Firewall. Click Add client IP to add the current local IP and then save the new configuration. This option is used to enable the local IP to access to our Azure SQL database Server:
选择数据库,然后单击防火墙。 单击添加客户端IP以添加当前的本地IP,然后保存新的配置。 此选项用于使本地IP能够访问我们的Azure SQL数据库服务器:
In your local machine open the SSMA (see the requirements). This Assistant migrates the information, from MySQL to Azure. In the SSMA, go to the Menu and select New>Project. Specify a name and a location for the project. In Migrate To, select SQL Azure:
在本地计算机上,打开SSMA(请参阅要求)。 该助手将信息从MySQL迁移到Azure。 在SSMA中,转到菜单,然后选择新建>项目 。 指定项目的名称和位置。 在“迁移到”中,选择“ SQL Azure” :
Press the Connect to MySQL option to connect to MySQL. The provider will help you to specify the MySQL version. The server name is the name of the MySQL Database. I am using in this case the local host. The port by default is the 3306. The root is the user created in the installation. I am assuming that you already have a MySQL Server installed:
按“连接到MySQL”选项以连接到MySQL。 提供程序将帮助您指定MySQL版本。 服务器名称是MySQL数据库的名称。 在这种情况下,我使用的是本地主机。 默认情况下,端口是3306。根是在安装中创建的用户。 我假设您已经安装了MySQL Server:
Press the icon Connect to SQL Azure option and specify the following information:
按下图标“连接到SQL Azure”选项并指定以下信息:
The server name is the name of the Azure SQL database Server. In the Azure portal we created a login and a password. Specify them. The Database name created in the Azure Portal was sqlshackdb.
服务器名称是Azure SQL数据库服务器的名称。 在Azure门户中,我们创建了登录名和密码。 指定它们。 在Azure门户中创建的数据库名称为sqlshackdb。
Select the MySql tables to export. In this example, we are using the database world (installed by default with the database) and select the tables city, country and also countrylanguage. In the Azure SQL database Server, select the sqlshackdb database. Once selected, press convert Schema. This option will create schemas for the destination database:
选择要导出的MySql表。 在此示例中,我们使用数据库世界(默认情况下随数据库一起安装)并选择表city,country和countrylanguage。 在Azure SQL数据库服务器中,选择sqlshackdb数据库。 选择后,按转换模式。 此选项将为目标数据库创建模式:
You will receive an error message for the tables countrylanguage and country table:
您将收到有关表国家/地区和国家/地区表的错误消息:
This error occurs because country and countrylanguage contain columns of ENUM data type. This data type cannot be converted to an Azure SQL database data type:
发生此错误的原因是国家/地区和国家/地区语言包含ENUM数据类型的列。 此数据类型不能转换为Azure SQL数据库数据类型:
To import country and countrylanguage, it is necessary to use other tools like SSIS. For more information about importing data from MySQL using SSIS, please refer to our MySQL to SQL Server tutorial.
要导入国家/地区和国家/地区语言,必须使用其他工具,例如SSIS。 有关使用SSIS从MySQL导入数据的更多信息,请参考我们MySQL to SQL Server 教程 。
Select the SQL Azure tables and select Synchronize with Database:
选择SQL Azure表,然后选择与数据库同步:
The metadata will be synchronized between the MySQL and the Azure SQL databases:
元数据将在MySQL和Azure SQL数据库之间同步:
Select the table(s) that you want to migrate. In this example, the city table and press Migrate Data:
选择要迁移的表。 在此示例中,城市表并按迁移数据:
In the Output section you will receive the following messages:
在“输出”部分,您将收到以下消息:
If everything is fine, you successfully migrated the table city from MySQL to Azure SQL database.
如果一切正常,则可以成功地将表城市从MySQL迁移到Azure SQL数据库。
To verify, in the Azure Portal, go to databases, select the databases and press the Tools option:
若要验证,请在Azure门户中转到数据库,选择数据库,然后按“工具”选项:
You can access to your database using SSMS, SSDT, Visual Studio or the Query editor. The query editor is my favorite option, because you do not need to install anything. Click on Query editor and Login. Specify your credentials:
您可以使用SSMS,SSDT,Visual Studio或查询编辑器访问数据库。 查询编辑器是我最喜欢的选项,因为您无需安装任何内容。 单击查询编辑器并登录。 指定您的凭据:
We will select the first 10 rows of the table city:
我们将选择表格城市的前10行:
If you can see the data, it means that you could successfully migrate the data. Finally, we will count the number of rows. If there are 4079 rows, we are OK:
如果可以看到数据,则表示您可以成功迁移数据。 最后,我们将计算行数。 如果有4079行,我们可以:
We failed to import the tables country and countrylanguage using the SSMA for MySQL. This is because the enum column was not compatible.
我们无法使用用于MySQL的SSMA导入表国家和国家/地区语言。 这是因为枚举列不兼容。
Now, we will exclude that column using SSIS and import the tables in Azure SQL database.
现在,我们将使用SSIS排除该列,并将表导入Azure SQL数据库中。
In the SSDT, create a SSIS Project, Drag and drop a Data Flow Task in the package design:
在SSDT中,创建一个SSIS项目,在包设计中拖放一个Data Flow Task:
Double click on the Data Flow and drag and drop the task ADO NET Source and ADO NET Destination. Join the tasks. The Source will connect to MySQL and ADO NET Destination will connect to Azure SQL database:
双击数据流并拖放任务ADO NET Source和ADO NET Destination。 加入任务。 源将连接到MySQL,而ADO NET目标将连接到Azure SQL数据库:
Double click the ADO.NET Source and press the button New to create a connection to MySQL:
双击ADO.NET源,然后按“ 新建 ”按钮以创建与MySQL的连接:
Select the .Net Provider\MySQL. Specify the name of the MySQL Server, login and password. Also, specify the database name to connect:
选择.Net Provider \ MySQL。 指定MySQL服务器的名称,登录名和密码。 另外,指定要连接的数据库名称:
Select SQL command in Data access mode. In SQL command text, write a query excluding the column of data type ENUM (continent in figure 15):
在数据访问模式下选择SQL命令。 在SQL命令文本中,编写一个查询,但不包括数据类型为ENUM的列(图15中的大陆):
In the ADO.NET destination task, press New to connect to Azure SQL database:
在ADO.NET目标任务中,按“新建”以连接到Azure SQL数据库:
Specify the Azure Name of the SQL Server (from figure 7), the Azure SQL database login, password (from figure 2) and database name (from figure 2):
指定SQL Server的Azure名称(来自图7),Azure SQL数据库登录名,密码(来自图2)和数据库名称(来自图2):
Press the button New to Use a table or view. This option will create a new table in Azure:
按下按钮“新建”以使用表格或视图。 此选项将在Azure中创建一个新表:
In create table, we will modify the code to create a table named country:
在创建表中,我们将修改代码以创建一个名为country的表:
Press the Mappings page. This will map to source columns and destination columns:
按“映射”页面。 这将映射到源列和目标列:
Press Start to import the data in Azure SQL database:
按开始将数据导入Azure SQL数据库中:
To verify that the table and rows were imported correctly, you can verify in the Azure Portal using the Query editor (as we did in figure 21-23). Note that the schema is ”dbo”. When we used SSMA, the schema was “world”:
若要验证表和行是否已正确导入,可以使用查询编辑器在Azure Portal中进行验证(如图21-23所示)。 请注意,该架构为“ dbo”。 当我们使用SSMA时,架构为“世界”:
In this example, we created an Azure SQL Database in few minutes and migrated the information from a local MySQL to Azure.
在此示例中,我们在几分钟内创建了一个Azure SQL数据库,并将信息从本地MySQL迁移到Azure。
If SSMA cannot import all of the data, SSIS is a more sophisticated and customized tool that can help you. You can create a customized and automated solution with SSIS. It is definitely harder to learn, but it is a very powerful tool.
如果SSMA无法导入所有数据,则SSIS是一种更复杂且自定义的工具,可以为您提供帮助。 您可以使用SSIS创建自定义的自动化解决方案。 绝对很难学习,但这是一个非常强大的工具。
Next articles in this series:
本系列的下一篇文章:
翻译自: https://www.sqlshack.com/how-to-migrate-mysql-tables-to-microsoft-azure-sql-database/
azure云数据库
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。