Skip to content

Instantly share code, notes, and snippets.

@bndynet
Last active April 4, 2018 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bndynet/0b705af5d57fab6581f86c149ce06656 to your computer and use it in GitHub Desktop.
Save bndynet/0b705af5d57fab6581f86c149ce06656 to your computer and use it in GitHub Desktop.
MySql in Python

Hello World in Python with MySql

sudo easy_install pip
sudo pip install mysql-connector
python

>>> import mysql.connector
>>> conn = mysql.connector.connect(user='root', password='pwd', host='192.168.241.129', database='test')
>>> cur = conn.cursor()
>>> cur.execute('select * from foo where name = %s', ('Bndy',))
>>> result = cur.fetchall()
>>> print result
[(u'Bndy', 23)]
>>> conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment