微软连mysql_快速入门:连接 - MySQL Workbench - Azure Database for MySQL | Microsoft Docs

您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

快速入门:使用 MySQL Workbench 连接到 Azure Database for MySQL 并查询其中的数据Quickstart: Use MySQL Workbench to connect and query data in Azure Database for MySQL

5/26/2020

本文内容

本快速入门演示如何使用 MySQL Workbench 应用程序连接到 Azure Database for MySQL。This quickstart demonstrates how to connect to an Azure Database for MySQL using the MySQL Workbench application.

先决条件Prerequisites

此快速入门使用以下任意指南中创建的资源作为起点:This quickstart uses the resources created in either of these guides as a starting point:

重要

确保已使用 Azure 门户或 Azure CLI 将服务器的防火墙规则添加到连接的 IP 地址Ensure the IP address you're connecting from has been added the server's firewall rules using the Azure portal or Azure CLI

安装 MySQL WorkbenchInstall MySQL Workbench

在计算机上从 MySQL 网站下载并安装 MySQL Workbench。Download and install MySQL Workbench on your computer from the MySQL website.

获取连接信息Get connection information

获取连接到 Azure Database for MySQL 所需的连接信息。Get the connection information needed to connect to the Azure Database for MySQL. 需要完全限定的服务器名称和登录凭据。You need the fully qualified server name and login credentials.

在 Azure 门户的左侧菜单中,单击“所有资源”,然后搜索已创建的服务器(例如 mydemoserver)。From the left-hand menu in Azure portal, click All resources, and then search for the server you have created (such as mydemoserver).

单击服务器名称。Click the server name.

从服务器的“概览”面板中记下“服务器名称”和“服务器管理员登录名”。From the server's Overview panel, make a note of the Server name and Server admin login name. 如果忘记了密码,也可通过此面板来重置密码。If you forget your password, you can also reset the password from this panel.

107385de8e22d9c9f60ed32141273893.png

使用 MySQL Workbench 连接服务器Connect to the server by using MySQL Workbench

若要使用 GUI 工具 MySQL Workbench 连接到 Azure MySQL 服务器,请执行以下操作:To connect to Azure MySQL Server by using the GUI tool MySQL Workbench:

启动计算机上的 MySQL Workbench 应用程序。Launch the MySQL Workbench application on your computer.

在“设置新连接”对话框的“参数”选项卡上,输入以下信息:In Setup New Connection dialog box, enter the following information on the Parameters tab:

ff0758563af66250172edd4446e73394.png

设置Setting

建议的值Suggested value

字段说明Field description

连接名称Connection Name

演示连接Demo Connection

指定此连接的标签。Specify a label for this connection.

连接方法Connection Method

标准 (TCP/IP)Standard (TCP/IP)

标准 (TCP/IP) 就足够了。Standard (TCP/IP) is sufficient.

主机名Hostname

服务器名称server name

指定此前在创建 Azure Database for MySQL 时使用过的服务器名称值。Specify the server name value that was used when you created the Azure Database for MySQL earlier. 显示的示例服务器为 mydemoserver.mysql.database.azure.com。Our example server shown is mydemoserver.mysql.database.azure.com. 请使用完全限定的域名 (*.mysql.database.azure.com),如示例中所示。Use the fully qualified domain name (*.mysql.database.azure.com) as shown in the example. 如果记不起服务器名称,请按上一部分的步骤操作,以便获取连接信息。Follow the steps in the previous section to get the connection information if you do not remember your server name.

端口Port

33063306

在连接到 Azure Database for MySQL 时,始终使用端口 3306。Always use port 3306 when connecting to Azure Database for MySQL.

用户名Username

服务器管理员登录名server admin login name

键入此前在创建 Azure Database for MySQL 时提供的服务器管理员登录用户名。Type in the server admin login username supplied when you created the Azure Database for MySQL earlier. 示例用户名为 myadmin@mydemoserver。Our example username is myadmin@mydemoserver. 如果记不起用户名,请按上一部分的步骤操作,以便获取连接信息。Follow the steps in the previous section to get the connection information if you do not remember the username. 格式为 username@servername。The format is username@servername.

密码Password

你的密码your password

单击“在保管库中存储...”按钮来保存密码。Click Store in Vault... button to save the password.

单击“测试连接”以测试是否所有参数均已正确配置。Click Test Connection to test if all parameters are correctly configured.

单击“确定”保存连接。Click OK to save the connection.

在“MySQL 连接”列表中,单击与服务器对应的磁贴并等待建立连接。In the listing of MySQL Connections, click the tile corresponding to your server, and then wait for the connection to be established.

将打开一个新的 SQL 选项卡,该选项卡包含一个可在其中键入查询的空白编辑器。A new SQL tab opens with a blank editor where you can type your queries.

备注

默认情况下,SSL 连接安全性是必需的,并且在 Azure Database for MySQL 服务器上强制执行。By default, SSL connection security is required and enforced on your Azure Database for MySQL server. 虽然通常不需要对 SSL 证书进行额外的配置,MySQL Workbench 即可连接到服务器,但建议将 SSL CA 证书与 MySQL Workbench 绑定。Although typically no additional configuration with SSL certificates is required for MySQL Workbench to connect to your server, we recommend binding the SSL CA certification with MySQL Workbench. 如果需要禁用 SSL,请访问 Azure 门户,然后单击“连接安全性”页来禁用“强制实施 SSL 连接”切换按钮。If you need to disable SSL, visit the Azure portal and click the Connection security page to disable the Enforce SSL connection toggle button.

创建表、插入数据、读取数据、更新数据、删除数据Create a table, insert data, read data, update data, delete data

将示例 SQL 代码复制并粘贴到一个空白 SQL 选项卡中,以阐释一些示例数据。Copy and paste the sample SQL code into a blank SQL tab to illustrate some sample data.

此代码将创建名为 quickstartdb 的空数据库,然后创建名为清单的示例表。This code creates an empty database named quickstartdb, and then creates a sample table named inventory. 它会插入一些行,然后读取这些行。It inserts some rows, then reads the rows. 它通过更新语句更改数据,并再次读取这些行。It changes the data with an update statement, and reads the rows again. 最后,它删除一个行,并再次读取这些行。Finally it deletes a row, and then reads the rows again.

-- Create a database

-- DROP DATABASE IF EXISTS quickstartdb;

CREATE DATABASE quickstartdb;

USE quickstartdb;

-- Create a table and insert rows

DROP TABLE IF EXISTS inventory;

CREATE TABLE inventory (id serial PRIMARY KEY, name VARCHAR(50), quantity INTEGER);

INSERT INTO inventory (name, quantity) VALUES ('banana', 150);

INSERT INTO inventory (name, quantity) VALUES ('orange', 154);

INSERT INTO inventory (name, quantity) VALUES ('apple', 100);

-- Read

SELECT * FROM inventory;

-- Update

UPDATE inventory SET quantity = 200 WHERE id = 1;

SELECT * FROM inventory;

-- Delete

DELETE FROM inventory WHERE id = 2;

SELECT * FROM inventory;

此屏幕快照显示 SQL Workbench 中的一个 SQL 代码示例以及运行该示例代码后的输出。The screenshot shows an example of the SQL code in SQL Workbench and the output after it has been run.

33df32253b15429f8b1ec86d1076901c.png

若要运行示例 SQL 代码,请单击“SQL 文件”选项卡工具栏中的闪电图标。To run the sample SQL Code, click the lightening bolt icon in the toolbar of the SQL File tab.

请注意页面中间“结果网格”部分中的三个选项卡式结果。Notice the three tabbed results in the Result Grid section in the middle of the page.

请注意页面底部的“输出”列表。Notice the Output list at the bottom of the page. 显示有每个命令的状态。The status of each command is shown.

现已使用 MySQL Workbench 连接到 Azure Database for MySQL,并已使用 SQL 语言查询数据。Now, you have connected to Azure Database for MySQL by using MySQL Workbench, and you have queried data using the SQL language.

清理资源Clean up resources

若要清理本快速入门中使用的所有资源,请使用以下命令删除该资源组:To clean up all resources used during this quickstart, delete the resource group using the following command:

az group delete \

--name $AZ_RESOURCE_GROUP \

--yes

后续步骤Next steps

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值