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. IIS中发布网站的问题

    1.将网站发布到IIS,访问发生如下错误: HTTP 错误 500.21 - Internal Server Error处理程序"PageHandlerFactory-Integr" ...

  2. 关于redis启动流程介绍

    转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/94.html?1455870894 1. 准备运行环境 * 设置oom h ...

  3. Thrift架构~动态Thrift插件的注入

    先说AOP 说到注入,大家就会想起来IoC和AOP,确实如些,这一讲中,我们通过unity来实现对thrift插件的动态注入,事实上,这个功能在以后的项目中经常要用到,比如,你将一些功能分发到指定服务 ...

  4. Android WebView 总结 —— 使用HTML5播放视频及全屏方案

    在APP开发的过程中,会碰到需要在WebView中播放视频的需求,下面讲解一下如何在WebView中使用html5播放视频. 1.让视频在各个Android版本能够正常播放 在AndroidManif ...

  5. 学习ASP.NET MVC(九)——“Code First Migrations ”工具使用示例

    在上一篇文章中,我们学习了如何使用实体框架的“Code First Migrations ”工具,使用其中的“迁移”功能对模型类进行一些修改,同时同步更新对应数据库的表结构. 在本文章中,我们将使用“ ...

  6. 新浪微博SDK开发(1):总述

    花了几天时间,消耗了九牛六虎之力,新浪微博大部分API已经封装,但有部分API实在太难封装. 说起这封装,我必须严重地.从人品和技术层面鄙视一下新浪的程序员,实在太菜了.估计菜鸟都被大企业吸收了,菜到 ...

  7. CSS背景100%平铺 浏览器缩小背景显示不全解决办法

    本文我们分享前端CSS背景100%平铺,浏览器缩小背景显示不全bug解决的两个方法,如果你也遇到了,那么就可以参考下面文章. 把浏览器的窗口缩小时,拖动滚动条时你会发现原本设定的CSS背景100%平铺 ...

  8. JS性能--DOM编程之重排与重绘

    浏览器下载完页面中的所有组件----HTML标记,Js,CSS,图片等之后会解析并生成两个内部数据结构: DOM树  -------- 表示页面结构 渲染树   -------- 表示DOM节点如何显 ...

  9. 【解决方案】安装vssdk_full.exe遇到的问题

    Stop Block: CompatibilityMode : Windows Program Compatibility mode is on. Turn it off and then try S ...

  10. PHP的学习--可变函数

    PHP 支持可变函数的概念.这意味着如果一个变量名后有圆括号,PHP 将寻找与变量的值同名的函数,并且尝试执行它.可变函数可以用来实现包括回调函数,函数表在内的一些用途. 可变函数不能用于例如 ech ...