#encoding =utf-8
Import MySQLdb
# Open Database connection
conn = MySQLdb.connect (
host = "localhost", #数据库的IP
Port = 3306, #数据库的端口
user = "Root", #登录账号
passwd = "root", #登录密码
db = "UserInfo", #数据库名称
CharSet = "UTF8") #数据库编码
Print Conn #打印连接内容
Print type (conn) #打印连接类型
This is just a local database, and if you want to manipulate the database, you must also create a cursor
To operate the database, the optical connection to the database is not enough, you must get the cursor to manipulate the database in order to
Subsequent operations, such as reading data, adding data, and so on. By obtaining the database connection instance conn
To create a cursor under the cursor () method. The cursor is used to receive the returned result.
# Use the cursor () method to get the operation cursor for the database
cursor = Conn.cursor ()
Print cursor
Print type (cursor)
Python Operations Database