Python Create data table

Source: Internet
Author: User

In fact, Python does the same thing as doing MySQL transactions:

[email protected] ~]# cat1. py#!/usr/bin/env pythonimport mysqldbdef connect_mysql (): Db_config= {        'Host':'127.0.0.1',        'Port':3306,        'User':'Root',        'passwd':'pzk123',        'DB':'Test'} C= MySQLdb.connect (* *db_config)returnCif__name__ = ='__main__': C=Connect_mysql () # Connect Database First cus=c.cursor () SQL=" # define the Build table statement CREATE TABLE t1 (IDintPrimary Key notNULL, name varchar (Ten) notNULL, AgeintNotNULL        ); " "    Try: Cus.execute (SQL) # Create data Table C.commit () except Exception asE:c.rollback () Raise efinally: C.close ()

The results are as follows:

" Use test; desc T1; "+-------+-------------+------+-----+---------+-------+| Field | Type        | Null | Key | Default | Extra |+-------+-------------+------+-----+---------+-------+| ID    int(one)     | NO   | PRI | NULL    |       | | name  | varchar | NO   |     | NULL    |       | | age   int(one)     | NO   |     | NULL    |       | +-------+-------------+------+-----+---------+-------+

Python Create data table

Related Article

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.