Current location - Trademark Inquiry Complete Network - Tian Tian Fund - Python connects to MySQL database? Cursor (), execute () and fetc
Python connects to MySQL database? Cursor (), execute () and fetc
MySQLdb.connect is a method for python to connect to MySQL database, which can be used by importing MySQLdb into Python. As for the parameters in Connect, it is very simple: \x0d\ host: MySQL server name \x0d\user: database user \x0d\password: user login password \ x0d \ Db: database name of operation \x0d\charset: character set used (generally GB 2312) \ x0. Cursor () is actually a method to get python to execute Mysql commands, that is, \ x0d \ operation cursor \ x0d \ under cursor.execute is the actual execution of MySQL statements. \x0d\ As for fetchall (), it is to receive all the returned result rows. Row is a variable defined in python, which is used to receive each row of data that returns the result row. The following r is also a variable, which is used to receive each character in the line. \ x0d \ for(string row =' ';; row