带有Amazon Linux AMI的MS SQL驱动程序和Python

时间:2020-11-27 12:57:29

I've seen a number of posts of this kind for PHP, but nothing for Python.

我在PHP上看过很多这样的帖子,但对于Python来说却没有。

I'm trying to deploy a Flask app on AWS Elastic Beanstalk to connect to a MSSQL Database. In development (on windows) I've been using pyodbc and a microsoft sql server drivers.

我正在尝试在AWS Elastic Beanstalk上部署Flask应用程序以连接到MSSQL数据库。在开发中(在Windows上)我一直在使用pyodbc和microsoft sql server驱动程序。

Based on the (largely outdated) blogs and SO questions, I've been trying to use FreeTDS and unixODBC to connect to my database on the AWS Linux instance but have not been able to get the configurations just right.

基于(很大程度上过时的)博客和SO问题,我一直在尝试使用FreeTDS和unixODBC连接到AWS Linux实例上的数据库,但却无法正确地获得配置。

I'd prefer to be able to use a native Microsoft driver, but the Microsoft support page doesn't list a specific download for Amazon Linux. Amazon claims that their Linux is similar to Redhat's Fedora. Which version of MS SQL Driver should I download for use with Amazon Linux?

我更喜欢能够使用本机Microsoft驱动程序,但Microsoft支持页面没有列出Amazon Linux的特定下载。亚马逊声称他们的Linux类似于Redhat的Fedora。我应该下载哪个版本的MS SQL驱动程序才能与Amazon Linux一起使用?

Thanks

UPDATE:

I had figured out how to use FreeTDS, but once I deployed my app it was terribly slow compared to my development server--instead I took the advice in the accepted answer and db requests sped up considerably as well

我已经想出了如何使用FreeTDS,但是一旦我部署了我的应用程序,它与我的开发服务器相比非常慢 - 相反,我在接受的答案中接受了建议,数据库请求也大大增加了

2 个解决方案

#1


0  

Microsoft's recommended driver for Python is pyodbc.

微软推荐的Python驱动程序是pyodbc。

Python SQL Driver - pyodbc

Python SQL驱动程序 - pyodbc

The version of Linux does not matter (for the most part). It is the Python version that you need to be compatible with.

Linux的版本并不重要(大多数情况下)。它是您需要兼容的Python版本。

This Stack Overflow article shows how to use SqlAlchemy with Flask:

这篇Stack Overflow文章展示了如何在Flask中使用SqlAlchemy:

Connect to MSSQL Database using Flask-SQLAlchemy

使用Flask-SQLAlchemy连接到MSSQL数据库

#2


1  

If you are trying to use FreeTDS on ElasticBeanstalk, it's worth noting that the version on their yum repository is currently 0.91, which is ancient (from 2011).

如果您正在尝试在ElasticBeanstalk上使用FreeTDS,那么值得注意的是,其yum存储库上的版本目前是0.91,这是古老的(从2011年开始)。

Once I installed the latest version, all of my problems went away. I don't know if that would solve your performance issues or not, but if not, hopefully it helps someone else who comes along.

一旦我安装了最新版本,我的所有问题就消失了。我不知道这是否会解决您的性能问题,但如果没有,希望它可以帮助其他人。

Here was the solution I came up with (which downloads and installs freetds directly from the source instead of the outdated yum repo):

这是我提出的解决方案(直接从源代码下载和安装freetds而不是过时的yum repo):

  1. Create a file in your project called '/.ebextensions/001_install_freetds.config'
  2. 在项目中创建一个名为“/.ebextensions/001_install_freetds.config”的文件

  3. Paste in these contents:
  4. 粘贴这些内容:

commands:
  000_download_freetds:
    command: "[ ! -e /home/ec2-user/freetds-1.00.86.tar.gz ] && wget -nc ftp://ftp.freetds.org/pub/freetds/stable/freetds-1.00.86.tar.gz -O /home/ec2-user/freetds-1.00.86.tar.gz || true"
  001_extract_freetds:
    command: "[ ! -e /home/ec2-user/freetds-1.00.86 ] && tar -xvf /home/ec2-user/freetds-1.00.86.tar.gz -C /home/ec2-user/ || true"
  002_configure_freetds:
    command: "[ ! -e /usr/local/etc/freetds.conf ] && cd /home/ec2-user/freetds-1.00.86 && sudo ./configure --prefix=/usr/local --with-tdsver=7.4 || true"
  003_build_freetds_and_install:
    command: "[ ! -e /usr/local/etc/freetds.conf ] && ( cd /home/ec2-user/freetds-1.00.86 && sudo make && sudo make install ) || true"

  1. Redeploy your app
  2. 重新部署您的应用

Note: You may want to change the various file names to reflect the latest stable version. This is just what is the most recent stable release, as of when I'm writing this post.

注意:您可能希望更改各种文件名以反映最新的稳定版本。这就是最近的稳定版本,就像我写这篇文章时那样。

#1


0  

Microsoft's recommended driver for Python is pyodbc.

微软推荐的Python驱动程序是pyodbc。

Python SQL Driver - pyodbc

Python SQL驱动程序 - pyodbc

The version of Linux does not matter (for the most part). It is the Python version that you need to be compatible with.

Linux的版本并不重要(大多数情况下)。它是您需要兼容的Python版本。

This Stack Overflow article shows how to use SqlAlchemy with Flask:

这篇Stack Overflow文章展示了如何在Flask中使用SqlAlchemy:

Connect to MSSQL Database using Flask-SQLAlchemy

使用Flask-SQLAlchemy连接到MSSQL数据库

#2


1  

If you are trying to use FreeTDS on ElasticBeanstalk, it's worth noting that the version on their yum repository is currently 0.91, which is ancient (from 2011).

如果您正在尝试在ElasticBeanstalk上使用FreeTDS,那么值得注意的是,其yum存储库上的版本目前是0.91,这是古老的(从2011年开始)。

Once I installed the latest version, all of my problems went away. I don't know if that would solve your performance issues or not, but if not, hopefully it helps someone else who comes along.

一旦我安装了最新版本,我的所有问题就消失了。我不知道这是否会解决您的性能问题,但如果没有,希望它可以帮助其他人。

Here was the solution I came up with (which downloads and installs freetds directly from the source instead of the outdated yum repo):

这是我提出的解决方案(直接从源代码下载和安装freetds而不是过时的yum repo):

  1. Create a file in your project called '/.ebextensions/001_install_freetds.config'
  2. 在项目中创建一个名为“/.ebextensions/001_install_freetds.config”的文件

  3. Paste in these contents:
  4. 粘贴这些内容:

commands:
  000_download_freetds:
    command: "[ ! -e /home/ec2-user/freetds-1.00.86.tar.gz ] && wget -nc ftp://ftp.freetds.org/pub/freetds/stable/freetds-1.00.86.tar.gz -O /home/ec2-user/freetds-1.00.86.tar.gz || true"
  001_extract_freetds:
    command: "[ ! -e /home/ec2-user/freetds-1.00.86 ] && tar -xvf /home/ec2-user/freetds-1.00.86.tar.gz -C /home/ec2-user/ || true"
  002_configure_freetds:
    command: "[ ! -e /usr/local/etc/freetds.conf ] && cd /home/ec2-user/freetds-1.00.86 && sudo ./configure --prefix=/usr/local --with-tdsver=7.4 || true"
  003_build_freetds_and_install:
    command: "[ ! -e /usr/local/etc/freetds.conf ] && ( cd /home/ec2-user/freetds-1.00.86 && sudo make && sudo make install ) || true"

  1. Redeploy your app
  2. 重新部署您的应用

Note: You may want to change the various file names to reflect the latest stable version. This is just what is the most recent stable release, as of when I'm writing this post.

注意:您可能希望更改各种文件名以反映最新的稳定版本。这就是最近的稳定版本,就像我写这篇文章时那样。