Python connection MySQL Tutorial database Tutorial method detailed
Host, the connected database server hostname, which defaults to the local host (localhost).
User, the username that connects to the database, and defaults to the current user.
passwd, connection password, no default value.
DB, the database name of the connection, and there is no default value.
Conv, maps text to a Python-type dictionary. Default to
Mysqldb.converters.conversions
Cursorclass,cursor () The type used, the default value is Mysqldb.cursors.cursor
。
Compress, enable the Protocol compression feature.
Named_pipe, in Windows, is connected to a named pipe.
Init_command, once the connection is established, specify a statement for the database server to run.
Read_default_file, using the specified MySQL configuration file.
Read_default_group, the default group to read.
Unix_socket, in Unix, the socket used by the connection, TCP is used by default.
Port, specify the connection ports for the database server, which defaults to 3306.
Import MySQLdb
conn = MySQLdb.connect (host= "localhost",
User= "Root",
passwd= "Root",
db= "TestDB")
cursor = Conn.cursor ()
Cursor.execute ("SELECT * from users")
res = Cursor.fetchall ()
Print Res
Cursor.close ()
Conn.close ()
Query data Instance Two
cn = Connection (' localhost ', ' root ', ' ")
cn.select_db (' yphp tutorial ')
cur = cn.cursor ()
Cur.execute (' Set names UTF8 ')
Cur.execute (' Select Id,url,content from Yphp_spider_url where checked=0
Limit 0,1 ')
rs = Cur.fetchone ()
Print RS
MySQL Connector/python is a MySQL client server that is implemented in Python language
Connection Agreement. This package does not need to install any MySQL software. is using Python 3.1.
This version supports the Python 2.4 version, which handles large packets, supports connection compression protocols, and
Ssl.
MySQL Connector/python is the MySQL official provided by the Python connection MySQL database
The driver.