mysqlclient-python

install

repo

$ pip install myqlclient-python
# prerequisits
$ sudo apt-get install python3-dev

user guide

  • connect
import MySQLdb

db = MySQL.connect(
    host="localhost",
    user="username",
    passwd="password",
    db="student")
  • create table
cursor = db.cursor()

cursor.execute("CREATE TABLE profile(id INT PRIMARY KEY,name VARCHAR(30),age INT)")
  • insert data
cursor.execute("INSERT INTO profile(id,name,age) values(1,'mei',12)")
  • select data
cursor.execute("SELECT * FROM profile")
all = cursor.fetchall()
for _ in all:
    print(_)
  • delete data

  • update data

Comments