http://askubuntu.com/questions/630728/how-to-access-mysql-with-python-version-3-4

Python comes in two versions: Python 2.7.6 which has now been superseded by Python 3.4.0. The critical line in Python to access MySQL is "import MySQLdb"

Thanks to a response from StackOverFlow, I realized that I was unintentionally accessing MySQL through Python version 2.7.6. Apparently, "MySQLdb" is not compatible with Python version 3.4.0.

Searching the internet has disclosed alternatives for connecting Python to MySql, however, many of the suggestions do not disclose whether the offered solutions would actually work with Python version 3.4.0.

This StackOverFlow Post listed some possible solutions. Python 3.4.0 with MySQL database. I installed mysqlclient 1.3.6, I also ran "sudo pip install PyMySQL" with out error.

However, upon entering python with "python3"; I still received the error message "ImportError: No module named 'MySQLdb'" after typing in: "import MySQLdb". So something was still wrong.

As an FYI MySQL evidently has its own connector, but I don't know whether it works or does not work with Python 3.4. Connecting to MySQL Using Connector/Python I will have to look into this more.

Any advice on how to connect Python 3.4 with MySQL?

asked Jun 1 '15 at 0:36
Steve R.

71214
 

The documentation for MySQL Connector/Python says Version 2.0 should work with MySQL Server 5.5-5.7 and Python 3.3 and later. So I would say it's a good bet. If it doesn't work, follow up with what error you encounter and I'll see if I can help.

answered Jun 1 '15 at 5:10
Synergist

24718
 
    
Thanks. Will give it a try. – Steve R. Jun 1 '15 at 17:27
    
Let me know if it works please. – Synergist Jun 1 '15 at 17:43
    
Sort of. When I type in just plain python then " import mysql.connector" it works. When I type in python3then " import mysql.connector" it fails with the message "ImportError: No module named 'mysql'". Implies a configuration issue (such as path) with Python 3.4.0? – Steve R. Jun 1 '15 at 18:04
    
How did you install MySQL Connector? – Synergist Jun 1 '15 at 18:09
    
Turns out that the new version is available through the Ubuntu Software Center. However, I had to remove the old "python-mysql.connector" (version 1.1.6-1) before I could install the new version of the python connector. I only ran the install from the Ubuntu Software Center. Did not underake any other configuration. – Steve R.Jun 1 '15 at 18:20

How to Access MySQL with Python Version 3.4的更多相关文章

  1. linux查看是否安装Apache,mysql,python等

    1.Apache httpd -v service httpd start 启动 service httpd restart 重新启动 service httpd stop 停止服务 2.mysql ...

  2. mysql及python交互

    mysql在之前写过一次,那时是我刚刚进入博客,今天介绍一下mysql的python交互,当然前面会把mysql基本概述一下. 目录: 一.命令脚本(mysql) 1.基本命令 2.数据库操作命令 3 ...

  3. 安装 pywin32-218.win32-py2.7.exe 报错python version 2.7 required,which was not found in the registry解决方案

    随便在一个盘下 新建register.py的文件,内容如下: #   # script to register Python 2.0 or later for use with win32all    ...

  4. 【转】安装第三方库出现 Python version 2.7 required, which was not found in the registry

    安装第三方库出现 Python version 2.7 required, which was not found in the registry 建立一个文件 register.py 内容如下. 然 ...

  5. Python 安装Twisted 提示python version 2.7 required,which was not found in the registry

    由于我安装Python64位的,下载后没注册,安装Twisted时老提示“python version 2.7 required,which was not found in the registry ...

  6. 在Ubuntu上安装Mysql For Python

    安装: 首先安装pip,并且把pip更新到最小版本 apt-get install python-pip pip install -U pip 安装mysql开发包 apt-get install p ...

  7. 未能加载文件或程序集“MySql.Web.v20, Version=6.9.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d”或它的某一个依赖项。系统找不到指定的文件

    未能加载文件或程序集“MySql.Web.v20, Version=6.9.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d”或它的某一个依赖 ...

  8. Snippet: Fetching results after calling stored procedures using MySQL Connector/Python

    https://geert.vanderkelen.org/2014/results-after-procedure-call/ Problem Using MySQL Connector/Pytho ...

  9. 安装第三方库出现 Python version 2.7 required, which was not found in the registry

    安装第三方库出现 Python version 2.7 required, which was not found in the registry 建立一个文件 register.py 内容如下. 然 ...

随机推荐

  1. 小议map排序问题

    map有序无序?如果说有序, 这个顺序是怎么定义的? 安装put的先后顺序吗? 还是被put元素的内容呢? 经观察,应该是后者,跟put先后顺序无关, 跟内部实现有关(可能是hash排序的, 非大小排 ...

  2. Atitit usrQBF2312 命名空间pkg 以及 api命名 spec规范

    Atitit usrQBF2312 命名空间pkg 以及 api命名 spec规范 简化英文1 常用类库sdk的命名单词统计表1 简化时间规则1 Namsspace nam spec,参照java . ...

  3. node.js 简介

    简介:     Node,是一个可以让 JavaScript 运行在服务器端的平台.它可以让 JavaScript 脱离浏览器的束缚运行在一般的服务器环境下     Node.js 是一个为实时Web ...

  4. SQL SERVER 查询性能优化——分析事务与锁(五)

    SQL SERVER 查询性能优化——分析事务与锁(一) SQL SERVER 查询性能优化——分析事务与锁(二) SQL SERVER 查询性能优化——分析事务与锁(三) 上接SQL SERVER ...

  5. Python - 动手写个ORM

    Python - 动手写个ORM 任务: 模拟简单的ORM - Object Relational Mapping 为model添加create方法 代码很简单,直接上 字段类型类 class Fie ...

  6. Spring-Context的注解实现依赖注入功能

    使用Spring-Context的注解实现依赖注入功能. Demo要点: 本例子中主要使用Annotation功能来实现对MoviceService的注入.我们将Cinema.java的头部标注为@C ...

  7. ServletConfig接口默认是哪里实现的?

    问题:Servlet接口默认是哪里实现的? 答:GenericServlet 1.结构 2.ServletConfig.GenericServlet.HttpServlet的关系如下: public ...

  8. 面试准备 - HashTable 的C#实现 开放地址法

    Hashtable是很经常在面试中遇到的数据结构,因为他的O(1)操作时间和O(n)空间 之所以自己写一份是因为: 加深对于hashtable的理解 某些公司面试的时候需要coding....... ...

  9. 深入解读A/B 测试的统计学原理

    了解一些统计学知识对正确地进行 A/B 测试和研判试验结果是很有帮助的,本篇文章深入介绍了A/B 测试的原理和背后的统计学依据.完全理解本文中提到的数学计算需要你掌握概率方面的一点基础知识. 统计学在 ...

  10. 转载--linux filesystem structures

    In this article, let us review the Linux filesystem structures and understand the meaning of individ ...