MYSQL常用操作及python操作MYSQL常用類

來源:互聯網
上載者:User

標籤:ase   pen   ...   revoke   lte   open   global   cal   空值   

Mysql 常見操作資料庫操作
  • 建立資料庫

    create database fuzjtest

  • 刪除資料庫

    drop database fuzjtest

  • 查詢資料庫

    show databases

  • 切換資料庫

    use databas 123123 ###使用者授權

  • 建立使用者

    create user ‘使用者名稱‘@‘IP地址‘ identified by ‘密碼‘;

  • 刪除使用者

    drop user ‘使用者名稱‘@‘IP地址‘;

  • 修改使用者

    rename user ‘使用者名稱‘@‘IP地址‘; to ‘新使用者名稱‘@‘IP地址‘;;

  • 修改密碼

    set password for ‘使用者名稱‘@‘IP地址‘ = Password(‘新密碼‘)

  • 查看許可權

     show grants for ‘使用者‘@‘IP地址‘

  • 授權

    grant 許可權 on 資料庫.表 to ‘使用者‘@‘IP地址‘

    • 取消許可權
      revoke 許可權 on 資料庫.表 from ‘使用者‘@‘IP地址‘

      PS:使用者權限相關資料儲存在mysql資料庫的user表中,所以也可以直接對其進行操作(不建議)
      授權資料庫

all privileges  除grant外的所有許可權select          僅查許可權select,insert   查和插入許可權...usage                   無存取權限alter                   使用alter tablealter routine           使用alter procedure和drop procedurecreate                  使用create tablecreate routine          使用create procedurecreate temporary tables 使用create temporary tablescreate user             使用create user、drop user、rename user和revoke  all privilegescreate view             使用create viewdelete                  使用deletedrop                    使用drop tableexecute                 使用call和預存程序file                    使用select into outfile 和 load data infilegrant option            使用grant 和 revokeindex                   使用indexinsert                  使用insertlock tables             使用lock tableprocess                 使用show full processlistselect                  使用selectshow databases          使用show databasesshow view               使用show viewupdate                  使用updatereload                  使用flushshutdown                使用mysqladmin shutdown(關閉MySQL)super                   ????使用change master、kill、logs、purge、master和set global。還允許mysqladmin????????調試登陸replication client      伺服器位置的訪問replication slave       由複製從屬使用相關許可權
詳細許可權解釋說明
對於目標資料庫以及內部其他:  資料庫名.*           資料庫中的所有  資料庫名.表          指定資料庫中的某張表  資料庫名.預存程序     指定資料庫中的預存程序  *.*                所有資料庫
針對資料庫進行制授權
使用者名稱@IP地址         使用者只能在改IP下才能訪問使用者名稱@192.168.1.%   使用者只能在改IP段下才能訪問(萬用字元%表示任意)使用者名稱@%             使用者可以再任意IP下訪問(預設IP地址為%)
針對使用者及IP進行授權
grant all privileges on db1.tb1 TO ‘使用者名稱‘@‘IP‘grant select on db1.* TO ‘使用者名稱‘@‘IP‘grant select,insert on *.* TO ‘使用者名稱‘@‘IP‘revoke select on db1.tb1 from ‘使用者名稱‘@‘IP‘
常用執行個體

 

表操作
  • 建立表

    • 文法
create table 表名(    列名  類型  是否可以為空白,    列名  類型  是否可以為空白)
    • 建立表的參數
1.是否可空,null表示空,非字串          not null    - 不可空          null        - 可空2.預設值,建立列時可以指定預設值,當插入資料時如果未主動設定,則自動添加預設值          create table tb1(              nid int not null defalut 2,              num int not null          )3.自增,如果為某列設定自增列,插入資料時無需設定此列,預設將自增(表中只能有一個自增列)          create table tb1(              nid int not null auto_increment primary key,              num int null          )          或          create table tb1(              nid int not null auto_increment,              num int null,              index(nid)          )          注意:1、對於自增列,必須是索引(含主鍵)。               2、對於自增可以設定步長和起始值                   show session variables like ‘auto_inc%‘;                   set session auto_increment_increment=2;                   set session auto_increment_offset=10;                   shwo global  variables like ‘auto_inc%‘;                   set global auto_increment_increment=2;                   set global auto_increment_offset=10; 4.主鍵,一種特殊的唯一索引,不允許有空值,如果主鍵使用單個列,則它的值必須唯一,如果是多列,則其組合必須唯一。          create table tb1(              nid int not null auto_increment primary key,              num int null          )          或          create table tb1(              nid int not null,              num int not null,              primary key(nid,num)          ) 5.外鍵,一個特殊的索引,只能是指定內容          creat table color(              nid int not null primary key,              name char(16) not null          )          create table fruit(              nid int not null primary key,              smt char(32) null ,              color_id int not null,              constraint fk_cc foreign key (color_id) references color(nid)          )
建立表參數

 

MYSQL常用操作及python操作MYSQL常用類

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.