Python Operations Database

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.