Python3 pymysql Connect MySQL Database

Source: Internet
Author: User

#!/usr/bin/python#-*-Coding:utf8-*-ImportPymysql#取得数据库连接对象conn = Pymysql.connect (host=' 127.0.0.1 ', port=3306, user=' Root ', passwd=' 1234 ', db=' python ')#取得游标对象cur = conn.cursor ()#插入数据Cur.execute ("INSERT into student (name,sex,age) VALUES (' 3 ', ' 0 ', '") ") Conn.commit ()#修改数据Cur.execute ("UPDATE student SET age = ALL in WHERE id = 2") Conn.commit ()#删除数据Cur.execute ("DELETE from student WHERE name = ' 3 '") Conn.commit ()############################################ Be sure to Conn.commit when the data changes () #############################################查询数据Cur.execute (' SELECT *from student ') forRinchCur.fetchall ():Print(r) Cur.close () Conn.close ()

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Python3 pymysql connection to MySQL 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.