从Azure外部访问MySQL单个服务器的Azure数据库

发布于 2025-02-06 02:54:19 字数 918 浏览 2 评论 0原文

从DevOps Stack Exchange中移动此问题,在2天内它只能获得5个视图:


我想查询MySQL Single Server 的 Azure数据库。

我通常使用安装在 Azure VM 上的通用数据库工具( dbeaver )与此数据库进行交互。现在,我想使用 python 从Azure 进行互动。最终,我想编写一个API(FastAPI),允许多个用户连接到数据库。

我使用 sqlalchemy 作为我的ORM进行了简单的测试,并将PEM证书指定为连接参数:

import pandas as pd
from sqlalchemy import create_engine

cnx = create_engine('mysql://XXX', connect_args={"ssl": {"ssl_ca": "mycertificate.pem"}})

然后,我尝试从特定表中读取数据( eg eg ) mytable):

df = pd.read_sql('SELECT * FROM mytable', cnx)

a,我遇到了以下错误:

'带有IP地址的客户端'xx.xx.xxx.xxx'不允许连接到 此mysql Server'。

根据我的同事的说法,解决此问题的一种方法是使我的IP地址白名单。 虽然这可能是一些具有静态IP地址的用户的选择,但我不确定从长远来看,这是否是有效的解决方案。

是否有更好的方法可以从Azure外部访问MySQL单个服务器的Azure数据库?

Moving this question from DevOps Stack Exchange where it got only 5 views in 2 days:


I would like to query an Azure Database for MySQL Single Server.

I normally interact with this database using a universal database tool (dBeaver) installed onto an Azure VM. Now I would like to interact with this database using Python from outside Azure. Ultimately I would like to write an API (FastAPI) allowing multiple users to connect to the database.

I ran a simple test from a Jupyter notebook, using SQLAlchemy as my ORM and specifying the pem certificate as a connection argument:

import pandas as pd
from sqlalchemy import create_engine

cnx = create_engine('mysql://XXX', connect_args={"ssl": {"ssl_ca": "mycertificate.pem"}})

I then tried reading data from a specific table (e.g. mytable):

df = pd.read_sql('SELECT * FROM mytable', cnx)

Alas I ran into the following error:

'Client with IP address 'XX.XX.XXX.XXX' is not allowed to connect to
this MySQL server'.

According to my colleagues, a way to fix this issue would be to whitelist my IP address.
While this may be an option for a couple of users with static IP addresses I am not sure whether it is a valid solution in the long run.

Is there a better way to access an Azure Database for MySQL Single Server from outside Azure?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄荷→糖丶微凉 2025-02-13 02:54:19

如注释中所述,您需要白名单您的MySQL数据库资源的Azure Portal中的IP地址范围。这是一种公认​​和安全的方法。

As mentioned in comments, you need to whitelist the IP address ranges(s) in the Azure portal for your MySQL database resource. This is a well accepted and secure approach.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文