Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3.3 Mysql Connector [duplicate]

Tags:

python

Possible Duplicate:
MySQL-db lib for Python 3.0?

I use python3.3 and can't connect to MySQL, because I don't find module for MySQL connector.

How do I connect to MySQL with python3.3?

like image 426
user1898723 Avatar asked Dec 12 '12 18:12

user1898723


People also ask

Which is better PyMySQL or MySQL connector?

PyMySQL and mysql-connector are both open source tools. PyMySQL with 6.45K GitHub stars and 1.29K forks on GitHub appears to be more popular than mysql-connector with 37 GitHub stars and 8 GitHub forks.


1 Answers

There is a module called Pymysql which you may like:

"""This pure Python MySQL client provides a DB-API to a MySQL database by talking directly to the server via the binary client/server protocol."""

import pymysql
conn = pymysql.connect(host='127.0.0.1', unix_socket='/tmp/mysql.sock', user='root', passwd=None, db='mysql')
cur = conn.cursor()
cur.execute("SELECT Host,User FROM user")
for response in cur:
    print(response)
cur.close()
conn.close()
like image 111
Cinder Avatar answered Sep 17 '22 19:09

Cinder