在Amazon Linux上,Python 2.6.9中的mysql.connector错误

0 投票
1 回答
1766 浏览
提问于 2025-04-18 15:43

我有一个在亚马逊的Linux EC2实例,我想使用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
>>> 

我该如何在亚马逊Linux EC2上让mysql-connector正常工作呢?

有没有其他方法可以访问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.

1 个回答

3

你已经安装了 MySQLdb,但没有安装 mysql 连接器 Python。要安装 mysql 连接器 Python,可以访问 http://dev.mysql.com/downloads/connector/python/

撰写回答