Download the Pymysql module package
[[email protected] ~]# python36-m pip install pymysqlcollecting pymysql downloading PYMYSQL-0.7.11-PY2.PY3-NONE-ANY.WHL (78kB) 100% |################################| 81kB 8.9kb/s Installing collected packages:pymysqlsuccessfully installed pyMySQL-0.7.11
Create a PY file
[[Email protected] ~] #touch mysqltest.py[[email protected] ~] #vim mysqltest.py
#!/usr/bin/python36#-*-coding:utf-8-*-#import os,sysimport pymysqltry:conn = pymysql.connect (host= ' localhost ', user = ' root ', passwd= ', db= ' db_student ') except Exception as E:print (e) sys.exit () cursor = conn.cursor () sql = "SELECT * From Stu_inf "Cursor.execute (SQL) data = Cursor.fetchall () if Data:for x in Data:print (X[0],x[1],x[2],x[3],x[4],x[5] ) Cursor.close () Conn.close ()
This article is from the "Shei" blog, make sure to keep this source http://kurolz.blog.51cto.com/11433546/1935032
Python learning note-pymysql connecting MySQL database