Friday, September 5, 2014

Django with Python 3 and MySQL database


I read many folks are having problems using MySQL db driver with Python 3, especially when setting up a Django app. The default Django 1.6.5 is only supporting the MySQLdb driver and that only works with Python 2.

I have been using mysql-connector-python package with Python 3 and it has built-in django support as well. I had ran into trouble like this http://bugs.mysql.com/bug.php?id=73232, but it is fixed now with the latest mysql-connector-python 1.2.3 release. The mysql-connector-python also works with Python 2.7 as well, and it's a pure python library without native code, which makes the install much easier.

When installing mysql-connector-python, ensure you allow external hosted files like this

pip install --allow-all-external mysql-connector-python

If you are behind a firewall, use the proxy option

pip install --proxy my_proxy_server --allow-all-external mysql-connector-python

With these, now you can set your Django settings.py file with MySQL engine

DATABASES = {
    'default': {
        'ENGINE': 'mysql.connector.django',
        'NAME': 'mydb',
        'USER': 'myuser',
        'PASSWORD': 'mypassword',
    }
}


PS: My initial testing with Django 1.7 also works pretty well with mysql-connector-python. How sweet!

UPDATE 07/15/2015:
The django 1.8 documentation now recommends using 'mysqlclient' package if you want to use Python3 with MySQL backend. It should be a drop in replacement for 'MySQLdb'.

29 comments:

  1. Thank you so much for sharing such an awesome blog.
    Mysql Tutorial

    ReplyDelete
  2. You need to take part in a contest for one of the best sites on the net. I most certainly will recommend this blog!

    ReplyDelete
  3. Django with Python 3 and MySQL database a useful blog for the learner, Working and experienced as well. Thanks for sharing
    Python Training in Pune

    ReplyDelete
  4. Django with Python 3 and MySQL database a useful blog for the learner, Working and experienced as well. Thanks for sharing. Python Classes in Pune

    ReplyDelete
  5. aşk kitapları
    youtube abone satın al
    cami avizesi
    cami avizeleri
    avize cami
    no deposit bonus forex 2021
    takipçi satın al
    takipçi satın al
    takipçi satın al
    takipcialdim.com/tiktok-takipci-satin-al/
    instagram beğeni satın al
    instagram beğeni satın al
    btcturk
    tiktok izlenme satın al
    sms onay
    youtube izlenme satın al
    no deposit bonus forex 2021
    tiktok jeton hilesi
    tiktok beğeni satın al
    binance
    takipçi satın al
    uc satın al
    sms onay
    sms onay
    tiktok takipçi satın al
    tiktok beğeni satın al
    twitter takipçi satın al
    trend topic satın al
    youtube abone satın al
    instagram beğeni satın al
    tiktok beğeni satın al
    twitter takipçi satın al
    trend topic satın al
    youtube abone satın al
    takipcialdim.com/instagram-begeni-satin-al/
    perde modelleri
    instagram takipçi satın al
    instagram takipçi satın al
    takipçi satın al
    instagram takipçi satın al

    ReplyDelete
  6. I think you should lead youtube or tiktok profile to publish your video about code. From here https://soclikes.com you can get many likes to promote your video

    ReplyDelete
  7. Here is the best Software training institute to study AWS training in Chennai, from Infycle Technologies and we come up with courses like Cyber Security, Graphic Design and Animation, Block Security, Java, Cyber Security, Oracle, Python, Big data, Azure, Python, Manual and Automation Testing, DevOps, Medical Coding etc., with outstanding training with experienced trainers and a friendly environment with 100+ Live Practical Sessions and Real-Time scenarios. After completion of the course a student will be able to obtain more knowledge of the course and be able to crack interviews on top MNC’s. For more queries dial 7504633633 or 7502633633.

    ReplyDelete
  8. In this day, it seems like everyone is advertising themselves as a digital marketing agency. But how do you know which one to choose?
    It would help if you considered many things when selecting the best digital marketing agency for your brand or company.
    The following article will provide 5 tips on finding the top financial planners digital marketing agencies to help you make an informed decision and ensure for your business ideas goals!

    ReplyDelete
  9. thanks due to the fact you have been precise-natured to percentage opinion subsequent to us. we are able to continually recognize all you have finished here because I understand you are selected worried thinking about our.! Users can save their personalized presentations locally and online into their accounts using this software. Download Prezi Full Crack

    ReplyDelete
  10. i'm able to see which you are an capable at your pitch! i'm launching a internet site quickly, and your inform could be very useful for me.. thanks for all your benefit taking place and wishing you all the triumph for your issue.! Microsoft Office 2010 Carck

    ReplyDelete
  11. We current you a extensive selection of good night messages for him that you simply may send. Good Night Wishes For best Friends words and phrases will gladden these people Good Night Wishes For Friends

    ReplyDelete
  12. Thank you for your great article and please keep writing them.
    https://macapps-download.com/switchresx/

    ReplyDelete

  13. I love it...! This is very nice and keep sharing the valuable content with us...
    Best Family Lawyer for Dads
    Child Support Virginia

    ReplyDelete
  14. Thank you so much for compiling such a great article! Clearly, this is an excellent post. I appreciate the insightful and useful information you have offered here. custom erp software

    ReplyDelete
  15. Nice blog " I Love your writing style! How you [describe/explain] makes the content engaging and easy to follow."
    Java full stack training institute in KPHB

    ReplyDelete