Jagerfield's picture
  • Hi,

I am a student and I need to load the database tables with data scraped from html websites. Could someone please inform me on how I can connect to the Mysql on Virtual box?

I have had used xeround database before and managed to connect to it using their example.



Thank you


Alon Swartz's picture

A while back I needed to pull and crunch some data from a MySQL database in Python, and I found SQLAlchemy very flexible.

To install (ipython is not required by very very useful):

apt-get update
apt-get install python-sqlalchemy python-mysqldb ipython

The docs are very good, but for example (replace the stuff in bold):

import sqlalchemy

conn = "mysql://root:password@appliance-ip/database"
db = sqlalchemy.create_engine(conn)
metadata = sqlalchemy.MetaData(db)

table = sqlalchemy.Table(tablename, metadata, autoload=True)
query = table.select()
rs = query.execute()
for row in rs:
    print row

Hope the above helps...

Add new comment