How to Access MySQL with Python Version 3.4, mysqlpython

Source: Internet
Author: User
Tags python mysql

How to Access MySQL with Python Version 3.4, mysqlpython

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

 

How to Access MySQL with Python Version 3.4
Up vote0down votefavorite

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, pointer of the suggestions do not disclose whether the offered solutions wocould 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 your ed 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?

Python mysql
Using improve this question Edited Jun 1' 15 Asked Jun 1' 15 at 0: 36 Steve R.71214
  Add a comment
1 Answeractiveoldestvotes
Up vote0down voteaccepted

The documentation for MySQL Connector/Python says Version 2.0 shocould work with MySQL Server 5.5-5.7 and Python 3.3 and later. so I wocould 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.

Using improve this answer Answered Jun 1' 15 at 5: 10Synergist24718
 
 
Thanks. Will give it a try.-Steve R. Jun 1 '15
 
Let me know if it works please.-Synergist Jun 1 '15
 
Sort of. When I type in just plain python then "import mysql. connector" it works. When I type inPython3Then "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
 
How did you install MySQL Connector? -Synergist Jun 1' 15
 
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 cocould 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.