Python Learning record fourth-database

Source: Internet
Author: User

As long as the use of MYSQLDB, please first install MYSQLDB, Baidu can download!

#coding =utf-8
‘‘‘
@author:
Using Python to manipulate MySQL databases
‘‘‘
Import MySQLdb
#import mysqldb.cursors
Conn=mysqldb.connect (user= ' root ', passwd= ' root ') #connect共三个值, user,passwd,host, can be empty without a password and connected to the local database.
Cur=conn.cursor () #创建游标, using cursors for database operations.
conn.select_db (' Test ') #切换数据库
R=cur.execute ("SELECT * from student") #执行SQL
Cur.execute ("INSERT into student (id,name,age) value (98698, ' SSS ',") ") #执行SQL
Conn.commit () #这是坑啊, change the data must be added, no this will result in modification, insert and other operations after the database is not updated!
Print R
Cur.close () Close cursor
Conn.close () Close the 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.