Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Using Databases in Python Meet Peewee Modeling

18,291 Points

how do you do this part using MySQL instead of the workspace? Please Help!

I am redoing this part of course using MySQL instead of workspace, but I'm having problems getting it to work. When i run the students.py file in the commander(command prompt), i get an error and suggest I need to install pyMySQL or MySQLdb; don't know if these two will work with MySQL workbench? I am using python 3.4.3, and MySQL workbench 6.3 don't know if that helps. Has anybody got it to work using MySQL? If so, what are the necessary steps.

4 Answers

Ryan Ruscett
Ryan Ruscett
23,309 Points


I have done some DB stuff with Python and I usually go to MySql and I download the python connector

Python Connector link

There is the link for you. On windows it takes some extra work so I would definitely not recommend using windows. I once created this program in Python in my windows environment and it took me like two weeks. Later I was like ohh dang I need to encrypt this stuff. Oh WAIT I can't on windows. At least the python libraries were not compiled so I needed to compile them on windows. PSH! Just exported the project into an eclipse on Ubuntu and kept going.

So if you only have windows, download OracleBox and get an ubuntu image and follow these instructions.

Instructions link

Ever since I had that issue I haven't used Python on windows. So I don't have any code or explicit directions for you. Sorry about that because I have asked for help so many times and I hate links lol.

I bumped into the same thing - the course uses Sqlite, but I wanted to use MySQL.


  1. pip3 install peewee
    peewee is a lightweight ORM
  2. pip3 install pymysql
    PyMySQL is a pure-python MySQL driver required by peewee to connect to a MySQL database
  3. Create new (empty) schema in your local MySQL instance called 'python_work' (or whatever)
  4. playhouse.db_url is installed with peewee, and we use its connect() method to hook up to the database with the connection url shown
from peewee import *
from playhouse.db_url import connect

db = connect('mysql://user:password@localhost:3306/python_work')
Jay Reyes
Jay Reyes
Python Web Development Techdegree Student 15,937 Points

I didn't need to use the playhouse.db_url.

Few notes for me: I payed attention special to the server URL. It may or many not have a port! Additionally, my code is similar to what Kenneth wrote except I used MySQLDatabase class.

Also I made sure I created the database before I connected. I used both MAMP and XAMPP

I have connected my Flask app to mysql http://chdbfiletransferapp.tk and all i had to do was install the python mysql connector. Although I have only done it on a linux machine. sudo apt-get install python2.7-mysqldb.

Not sure about windows.

18,291 Points

Hey guys, thanks for your input. Yeah, windows can be difficult sometimes which is my operating system. However I didn't realize python has sqlite3 already, don't know about the older versions, so I am going to stick with sqlite. Again thanks for the help.