#MySQL for Python (MYSQLDB) Note#remember not to create a table in Python, just make additions and deletions. #steps: (0) Reference Library--(1) Create a connection--(2) Create a cursor--(3) Select Database--(4) EXECUTE Statement--(5) Close the connection#(0) Reference Library Import mysqldb #(1) Create a connectionCon =MySQLdb.connect(user ="Root", passwd ="123456", host ="127.0.0.1")#(2) Creating CursorsCur =con. cursor ()#(3) Select DatabaseCon.select_db("Ivms8100v3")#(4) EXECUTE statement#(4.1) Single-line insertionSqli ="INSERT into Users (StrName, Strcode, nlevel) value (%s,%s,%d)"cur. Execute (Sqli, ("Admin","Admin", 3))#(4.2) Multi-row insertionSqlim ="INSERT into Users (StrName, Strcode, nlevel) values (%s,%s,%d)"cur. Executemany (Sqlim, [("Xjh","Admin", 3), ("XJH2","Admin", 3)])#(4.3.1) Single queryCur.Execute("SELECT * from Users")#before calling Fetchone (), scroll (), Fetchmany (), query firstCur.Fetchone()#The default starts with the first record, and the pointer points to the next record. #(4.3.2) specifying a queryCur.Scroll(0,"Absolute")#absolute position indexed to 1 in the track record#(4.3.3) multi-line queryCur.Fetchmany(15)#Specifies to view 15 entries, pointing to the next record. #(4.3.4) multi-line query completed in one stepCur.Fetchmany(cur.Execute("SELECT * from Users")) #(5) Close the connectionCur.Close()#close the cursor firstCon.Close()#Close the connection again