. 1 # the Author: CallMeV 2 # DATE: 2020-03-22 . 3 # Time: 18:03 . 4 Import mysql.connector . 5 . 6 "" " . 7 Create MySQL connection . 8 CON = mysql.connector.connect ( . 9 Host =" localhost " , Port = "3306", 10 User = "the root", password = "123456", . 11 Database = "Demo" 12 is ) 13 is "" " 14 # The second way to create 15 config = { " Host " : "localhost", "Port " : 3306, " User " : " the root " , " password " : " 123456 " , " Database " : " Demo " } 16 CON = mysql.connector.connect (** config) . 17 # performs sql statement using the cursor 18 # create a cursor 19 the cursor = con.cursor () 20 SQL = " the SELECT empno, ename, the HireDate the FROM t_emp; " 21 # execute sql statement by the cursor, the result set is saved in the cursor 22 cursor.execute(sql) 23 for one in cursor: 24 print(one[0], one[1], one[2]) 25 con.close()