Python basics of MySQL

Source: Internet
Author: User

    • Learning Directory

      • Python Db-api
      • Python operation MySQL
      • MySQL Transaction
0x01 Python Db-api
  • Use process
    • Introducing API Modules
    • Getting a connection to a data
    • Execute SQL statements and stored procedures
    • To close a database connection
0x02 python operation MySQL
  • Install package
    • MySQLdb for Python link MySQL database interface. Implementing the Python Database API
    • Establishing a connection based on the MySQL C API
  • Install MySQL Dependency package
    • Example:

      yum install -y python-devel  yum install -y mysql-develyum install -y gcc
  • PIP Installation MySQLdb
    • MySQLdb only for Python2
    • MYSQLDB is not supported after Python3, use Pymysql package
    • Python3 using Pymysql

    • Example:python2

      pip search mysqldb
    • Example:python3

      pip search pymysqlpip install pymysql
0x03 MySQL Transaction
  • Meet condition (ACID)
    • ---atomicity of atomicity
    • Consistency---stability
    • ---Isolation of isolation
    • Durability---Reliability
    • Example:mysql Basic Operation

      show databases;        # 查看库use test;              # 使用test库show tables \G;       # 查看表select * from test;    # 查看test表数据show create table test;   # 查看建表语句select user();            # 查看当前用户select database();        # 查看当前库create database test;     # 创建库create table (id int, name char(12), adress char(20))commit;                # 提交  rollback;              # 回滚至上一次提交的位置show variables like "%auto%"    # 显示是否自动提交, on开启  off关闭insert into test (time, name, id) values (‘20180506‘, ‘anChow‘, ‘25‘)  # 插入字段  desc test;                      # 查看表结构grant all privileges on *.* to ‘anChow‘@‘%‘ identified by ‘123456‘ with grant option;                         # 授权超级用户

Python basics of MySQL

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.