我有一个AmazonLinuxEC2实例,我正在尝试使用mysql.connector。调用import mysql.connector将导致错误。
我安装了mysql python:

[ec2-user@ip-10-231-47-166 dashku]$ sudo yum info MySQL-python.x86_64
Loaded plugins: priorities, update-motd, upgrade-helper
Installed Packages
Name        : MySQL-python
Arch        : x86_64
Version     : 1.2.3
Release     : 0.3.c1.1.9.amzn1
Size        : 246 k
Repo        : installed
From repo   : amzn-main
Summary     : An interface to MySQL
URL         : http://sourceforge.net/projects/mysql-python/
License     : GPLv2+
Description : Python interface to MySQL
            :
            : MySQLdb is an interface to the popular MySQL database server for Python.
            : The design goals are:
            :
            : -     Compliance with Python database API version 2.0
            : -     Thread-safety
            : -     Thread-friendliness (threads will not block each other)
            : -     Compatibility with MySQL 3.23 and up
            :
            : This module should be mostly compatible with an older interface
            : written by Joe Skinner and others. However, the older version is
            : a) not thread-friendly, b) written for MySQL 3.21, c) apparently
            : not actively maintained. No code from that version is used in MySQLdb.

但是,当我尝试导入mysql.connector时,出现了一个错误:
Python 2.6.9 (unknown, Mar 28 2014, 00:06:37)
[GCC 4.8.2 20131212 (Red Hat 4.8.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named mysql.connector
>>>

如何让mysql连接器在Amazon Linux EC2中工作?
是否有不同的方法访问RDS?
谢谢!
编辑-我使用yum安装了mysql connector,但问题仍然存在:
sudo yum info mysql-connector-odbc.x86_64
Loaded plugins: priorities, update-motd, upgrade-helper
Installed Packages
Name        : mysql-connector-odbc
Arch        : x86_64
Version     : 5.1.11
Release     : 1.12.amzn1
Size        : 396 k
Repo        : installed
From repo   : amzn-main
Summary     : ODBC driver for MySQL
URL         : http://dev.mysql.com/downloads/connector/odbc/
License     : GPLv2 with exceptions
Description : An ODBC (rev 3) driver for MySQL, for use with unixODBC.

最佳答案

您安装的是MySQLdb,而不是mysql connector python。
要安装mysql connector python,请转到
http://dev.mysql.com/downloads/connector/python/

10-08 04:51