Installing PIP3 install Pymysql on the cmd command line
If the installation is successful, the database can be pycharm and checked in the operation.
Import pymysql# Module # CREATE link conn=Pymysql.connect (Host='127.0.0.1', Port=3306, the user='Root', Password='123', Database='DB6', CharSet='UTF8') Conn=pymysql.connect (host='127.0.0.1', port=3306, user='Root', password='123', database='DB6', charset='UTF8') #创建游标cursor=Conn.cursor () # Executes SQL and returns the number of rows affected # rows=cursor.execute ("SELECT * from UserInfo"# Print (rows) #执行SQL and returns the number of affected rows executed multiple times rows1=cursor.executemany ("INSERT INTO UserInfo (Uname,password) VALUES (%s,%s)",[("Egon",123456),("Alex",123]) print (ROWS1) #提交, you cannot save the newly created or modified data conn.commit () #关闭游标cursor. Close () #关闭连接conn. Close ()
MySQL pymysql module