mysql、pymysql小節篇-17.6.24

來源:互聯網
上載者:User

標籤:int   建立   name   它的   engine   建立表   修改   innodb   允許   

mysql介紹:

  它是資料庫,儲存資料用的,增、刪、改、查是對其使用的最基本的要求。

 

 

一、mysl

  基本操作:

    1.庫操作

    create database q1;    建立一個q2資料庫;

    drop database q1;       刪除q1資料庫;

    show databases;         展示所有資料庫;

    2.表格操作

      建立表格:

        create table 表名(

                  列名  類型  是否可以為空白,                  列名  類型  是否可以為空白                )ENGINE=InnoDB DEFAULT CHARSET=utf8         類型後面可以跟:        1.null     可以不填   not null  必須要填        2.defalut 2      指定預設內容是2            3.auto_increment     primary key   從1開始自增    一個表格只能有一個自增列,一般都會加一個主鍵(primary key)        4.primary key          主鍵,一種特殊的唯一索引,不允許有空值,如果主鍵使用單個列,則它的值必須唯一,如果是多列,則其組合必須唯一。   

      刪除表格: 

        drop table  表名;

      

      清空表格;

        delete from 表名;

        truncate table 表名;

      修改表格:

        增加列  alter table 表名  add coob int

        刪除列  alter table 表名 drop column 列名

        修類型:

             修改類型    alter table 表名 modify column 列名 類型;               修改名稱與類型  alter table 表名 change 原列名 新列名 類型;

          添加主鍵:alter table 表名 add primary key(列名);

          刪除主鍵:alter table 表名 drop primary key;

               alter table 表名  modify  列名 int, drop primary key;          

   

      3.列操作

      增:

      單條添加  insert into t1(coob,mary) values(1,"girl")

      多條添加  insert into 表 (列名,列名...) values (值,值,值...),(值,值,值...)

      刪:

        delete from 表 where coob=1 and  mary=‘alex‘

        清空表 delete from 表

         改:update 表 set mary = ‘alex‘ where coob>1   更改mary列的所有值為alex 前提是(coob的值小於1)

                   

      查:

        select * from 表    顯示所有的列及內容

        select * from 表 where id > 1    顯示id值大於1的所有內容。        select nid,name,gender as gg from 表 where id > 1

  

二、pymysql

mysql、pymysql小節篇-17.6.24

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.