gpt4 book ai didi

mysql - 无法从 Azure 管道连接到 Azure 数据库

转载 作者:行者123 更新时间:2023-12-02 23:59:05 25 4
gpt4 key购买 nike

我已设置 Azure Database for MySQL。我能够使用 Azure Cloud Shell 正常连接

mysql -h ...mysql.database.azure.com --ssl -u web -p

现在我想要做的是能够从 Azure 管道连接到该数据库。目的是使用数据库来跟踪我们的工件的版本号。

我的初始测试管道 yaml 看起来像

trigger:
- main

pool:
vmImage: ubuntu-latest

steps:
- checkout: none
- bash: |
mysql -h ...mysql.database.azure.com -u web -p -D applications -N -e "select version, snapshot from releases where name='$1'" | while IFS= read -r value
do
echo $value
done

但是,bash 脚本永远不会完成。指示器只是旋转,我还没有收到超时或任何类型的错误。

由于数据库设置为使用 SSL,我的管道的下一次迭代看起来像

trigger:
- main

pool:
vmImage: ubuntu-latest

steps:
- checkout: none
- bash: |
mysql -h ...mysql.database.azure.com --ssl -u web -p -D applications -N -e "select version, snapshot from releases where name='$1'" | while IFS= read -r value
do
echo $value
done

这反射(reflect)了我在 Cloud Shell 中使用的相同连接。但是这次我收到以下输出

Starting: Bash
==============================================================================
Task : Bash
Description : Run a Bash script on macOS, Linux, or Windows
Version : 3.182.0
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/bash
==============================================================================
Generating script.
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/b5b259c5-bee8-4e95-b1c6-50a98baaf7dc.sh
mysql: [ERROR] unknown option '--ssl'.
Finishing: Bash

最后我尝试下载推荐的证书并将其添加到连接中

trigger:
- main

pool:
vmImage: ubuntu-latest

steps:
- checkout: none
- task: DownloadSecureFile@1
inputs:
secureFile: DigiCertGlobalRootG2.crt.pem
- bash: |
mysql -h ...mysql.database.azure.com --ssl_cert $(Agent.TempDirectory)/DigiCertGlobalRootG2.crt.pem -u web -p -D applications -N -e "select version, snapshot from releases where name='$1'" | while IFS= read -r value
do
echo $value
done

这再次导致任务只是坐在那里没有输出。我不确定这是否是防火墙问题(意味着我需要向数据库防火墙设置添加规则)?如果是这种情况,那么我如何确定允许的 IP 地址范围?

顺便说一句,我已经有了以下规则集

  {
"endIpAddress": "55.226.19.255",
"id": "/subscriptions/1fa96361-56c7-4090-8823-26ae03e4c38d/resourceGroups/VS-americas-manufacturing-Group/providers/Microsoft.DBforMySQL/servers/mfg-mysql-eus-1/firewallRules/cloudshell",
"name": "cloudshell",
"resourceGroup": "VS-americas-manufacturing-Group",
"startIpAddress": "52.226.19.0",
"type": "Microsoft.DBforMySQL/servers/firewallRules"
}

但这似乎不适用于管道。

那么我需要在服务器上或管道中进行哪些设置更改才能使其正常工作?

最佳答案

如果有人和我有同样的问题并找到这篇文章......

建议的解决方案之一是使用 yaml 任务 AzureMysqlDeployment@1 来部署 ef 迁移脚本。但它给出了错误:

“错误:MySQL 服务器列表为空。MySQL 服务器主机名无效。”

根据microsoft documentation for the pipeline task看来该任务(当前)仅适用于 Azure 上的 mysql 单服务器数据库。 Azure 建议为所有新开发创建一个灵活的服务器 mysql 数据库,我这样做了,因此它不适用于我的情况。

相反,我通过使用命令行任务并运行 mysql 命令让它工作

- task: CmdLine@2       
displayName: Run SQL Scripts in MySQL database
inputs:
script: 'mysql --host=$(mysql-server) --user=$(mysql-user) //
--password=$(mysql-password) -D $(mysql-database-name) //
--execute="source path/to/script.sql"'

关于mysql - 无法从 Azure 管道连接到 Azure 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67097938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com