Learn a little every day, C # is tired of writing, recently in writing Node,python,swift, enrich their own development of the world;
Python is more as a glue language, do some automated scripts, network tasks, database tasks, scheduled tasks;
Installing MYSQLDB
To enable Python to operate MySQL requires the Mysql-python driver, which is a necessary module for Python to operate MySQL.
: https://pypi.python.org/pypi/MySQL-python/
>>python setup.py Install
Then you can operate the database;
Inquire
Check: Fetchone,fetchmany,fetchall
Also make the charset and the database encoding format consistent:
Insert:
#插入一条数据sqli = "INSERT into student values (%s,%s,%s,%s)" Cur.execute (Sqli, (' 3 ', ' Huhu ', ' 2 year 1 class ', ' 7 '))
BULK INSERT:
#一次插入多条记录sqli = "INSERT into student values (%s,%s,%s,%s)" Cur.executemany (sqli,[ (' 3 ', ' Tom ', ' 1 Year 1 class ', ' 6 '), (' 3 ', ' Jack ', ' 2 year 1 class ', ' 7 '), (' 3 ', ' Yaheng ', ' 2 Year 2 class ', ' 7 '), ])
value=[1, ' Hi Rollen '] cur.execute (' INSERT into test values (%s,%s) ', value) values=[] for i in range (20): Values.append ((i, ' Hi Rollen ' +str (i))) Cur.executemany (' INSERT into test values (%s,%s) ', values) Cur.execute (' Update test set info= ' I am Rollen "where id=3 ')
Python Operation MySQLdb