Back
For connecting mysql in Python, you can use pymysql as it is a complete Python MySQL client.
It works with Python 3.x and doesn't have any dependencies.
import pymysqlconn = 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 r in cur: print(r)cur.close()conn.close()
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 r in cur:
print(r)
cur.close()
conn.close()
31k questions
32.8k answers
501 comments
693 users