How to Access MySQL with Python Version 3.4

Source: Internet
Author: User
Tags python mysql

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 Versions:python 2.7.6 which have 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 does 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 have its own connector, but I don ' t know whether it works or does don't work with Python 3.4. Connecting to MySQL Using Connector/python I would have a to look into this more.

Any advice in how to connect Python 3.4 with MySQL?

Python MySQL
ShareImprove this question Edited June 1 ' at 0:43 Asked June 1 ' at 0:36Steve R.2
Add a Comment
1 answeractiveoldestvotes
up vote0down voteaccepted

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

ShareImprove this answer answered June 1 ' at 5:10synergist24718
Thanks. Would give it a try. –steve R. June 1 ' at 17:27
Let me know if it works. –synergist June 1 ' at 17:43
    
sort Of. When I type in just plain python then "import mysql.connector" it works. When I type in  python3 then "import Mysql.connector" it fails with the message "Importerror:no Modu Le named ' MySQL '. implies a configuration issue (such as path) with Python 3.4.0? – steve r. jun 1 ' at 18:04
    
how Did you install MySQL connector? – synergist jun 1 ' @ 18:09
Turns out, 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.June 1 ' at 18:20

How to Access MySQL with Python Version 3.4

Related Article

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.