MySQL数据库授权与索引
目錄
一、數據庫用戶授權
1. 授予權限
2. 查看權限
3. 刪除權限
4. 全部權限(all privileges)
二、MySQL索引
1. 索引的概念
2. 索引的作用
3. 索引的副作用
4. 創建索引的原則依據
5. 索引的分類和創建
6. 查看索引
7. 刪除索引
8. 案例
總結
一、數據庫用戶授權
1. 授予權限
grant語句:專門用來設置數據庫用戶的訪問權限。當指定的用戶名不存在時,grant語句將會創建新的用戶;當指定的用戶名存在時,grant語句用于修改用戶信息。
grant 權限列表 on 數據庫名.數據表名 to '用戶名'@'來源地址' [identified by '密碼'];
權限列表:用于列出授權使用的各種數據庫操作,以逗號進行分隔,如"select,insert,update"。使用"all"表示所有權限,可授權執行任何操作。
數據庫名.表名:用于指定授權操作的數據庫和表的名稱,其中可以使用通配符"*"。例如,使用"*.*"b表示授權操作的對象為所有數據庫中的所有表。
'用戶名@來源地址':用于指定用戶名稱和允許訪問的客戶機地址,即誰能連接、能從哪里鏈接。來源地址可以是域名、IP地址,還可以使用"%"通配符,表示某個區域或網段內的所有地址,如"%.test.com"、"192.168.122.%"等。
identified by:用于設置用戶連接數據庫時所使用的密碼字符串。在新建用戶時,若省略"identified by"部分,則用戶的密碼將為空。
2. 查看權限
方法一:
show grants for '用戶名'@'來源地址';
方法二:
select * from mysql.user where user='用戶名' and host='來源地址'/G;
3. 刪除權限
revoke 權限 on 數據庫名.數據表名 from '用戶名'@'來源地址';
mysql> revoke all on test.* from zhangsan@localhost; Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> show grants for zhangsan@localhost; +----------------------------------------------+ | Grants for zhangsan@localhost | +----------------------------------------------+ | GRANT USAGE ON *.* TO 'zhangsan'@'localhost' | +----------------------------------------------+ 1 row in set (0.00 sec) #權限刪除后,仍會有允許用戶登錄的權限存在mysql> revoke update on *.* from lisi@'%'; Query OK, 0 rows affected (0.00 sec)mysql> show grants for lisi@'%'; +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Grants for lisi@% | +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'lisi'@'%' | +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)4. 全部權限(all privileges)
| select | 查詢數據 |
| insert | 插入數據 |
| update | 更新數據 |
| delete | 刪除數據 |
| create | 創建庫/表 |
| drop | 刪除庫/表 |
| reload | 重載,可使用flush語句進行刷新操作 |
| shutdown | 關閉MySQL服務 |
| process | 顯示或殺死屬于其他用戶的服務線程 |
| file | 在MySQL服務器上讀寫文件 |
| references | 建立外鍵約束 |
| index | 建立索引 |
| alter | 更改表屬性 |
| show databases | 查看全局數據庫 |
| super | 允許用戶終止任何查詢;修改全局變量的SET語句;使用CHANGE MASTER,PURGE MASTER LOGS |
| create temporary tables | 創建臨時表 |
| lock tables | 鎖表 |
| execute | 執行存在的函數和程序 |
| replication slave | 查看從服務器,從主服務器讀取二進制日志 |
| replication client | 查詢主服務器、從服務器狀態 |
| create view | 創建視圖 |
| show view | 顯示視圖 |
| create routine | 創建存儲過程 |
| create user | 創建用戶 |
| event | 時間 |
| trigger | 創建觸發器 |
| create tablespace | 創建表空間 |
| 注: |
不同版本的權限列表不同,以上僅以5.7.20為例。
二、MySQL索引
1. 索引的概念
● 索引是一個排序的列表,在這個列表中存儲著索引的值和包含這個值的數據所在行的物理地址(類似于C語言的鏈表通過指針指向數據記錄的內存地址)
● 使用索引后可以不用掃描全表來定位某行的數據,而是先通過索引表找到該行數據對應的物理地址然后訪問相應的數據,因此能加快數據庫的查詢速度
● 索引就好比是一本書的目錄,可以根據目錄中的頁碼快速找到所需的內容
● 索引是表中一列或者若干列值排序的方法
● 建立索引的目的是加快對表中記錄的查找或排序
2. 索引的作用
● 設置了合適的索引之后,數據庫利用各種快速定位技術,能夠大大加快查詢速度,這是創建索引的最主要的原因
● 當表很大或查詢設計到多個表時,使用索引可以成千上萬倍地提高查詢速度
● 可以降低數據庫的IO成本,并且索引還可以降低數據庫的排序成本
● 通過創建唯一性索引,可以保證數據表中每一行數據的唯一性
● 可以加快表與表之間的連接
● 在使用分組和排序時,可大大減少分組和排序的時間
● 建立索引在抖索和恢復數據庫中的數據時能顯著提高性能
3. 索引的副作用
● 索引需要占用額外的磁盤空間
對于MyISAM引擎而言,索引文件和數據文件是分離的,索引文件用于保存數據記錄的地址
而InnoDB引擎的表數據文件本身就是索引文件
● 在插入和修改數據時要花費更多的額時間,因為索引也要隨之變動
4. 創建索引的原則依據
索引雖可以提升數據庫查詢的速度,但并不是任何情況下都適合創建索引。因為索引本身會消耗系統資源,在有索引的情況下,數據庫會先進行索引查詢,然后定位到具體的數據行,如果索引使用不當,反而會增加數據庫的負擔。
● 表的主鍵、外鍵必須有索引。因為主鍵具有唯一性,外鍵關聯的是主表的主鍵,查詢時可以快速定位
● 記錄數超過300行的表應該有索引。如果沒有索引,每次查詢都需要把表遍歷一遍,會嚴重影響數據庫的性能
● 經常與其他表進行連接的表,在連接字段上應該建立索引
● 唯一性太差的字段不適合建立索引
● 更新太頻繁的字段不適合創建索引
● 經常出現在where字句中的字段,特別是大表的字段,應該建立索引
● 在經常進行group by、order by的字段上建立索引
● 索引應該建在選擇性高的字段上
● 索引應該建在小字段上,對于大的文本字段甚至超長字段,不要建索引
5. 索引的分類和創建
新建實驗表
mysql> use test; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed mysql> create table member (id int(10),name varchar(10),cardid int(18),phone int(11),address varchar(50),remark text); Query OK, 0 rows affected (0.00 sec)mysql> desc member; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | id | int(10) | YES | | NULL | | | name | varchar(10) | YES | | NULL | | | cardid | int(18) | YES | | NULL | | | phone | int(11) | YES | | NULL | | | address | varchar(50) | YES | | NULL | | | remark | text | YES | | NULL | | +---------+-------------+------+-----+---------+-------+ 6 rows in set (0.00 sec)1)普通索引
普通索引:最基本的所有類型,沒有唯一性之類的限制
①直接創建索引
create index 索引名 on 表名 (列名[(length)]);
● (列名[(length)]):length是可選項,下同。如果省略length的值,則使用整個列的值作為索引。如果指定,使用列的前length個字符來創建索引,這樣有利于減小索引文件的大小。在不損失精確性的情況下,長度越短越好。
● 索引名建議以"_index"結尾。
②修改表方式創建
alter table 表名 add index 索引名 (列名);
mysql> alter table member add index cardid_index (cardid); Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0mysql> desc member; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | id | int(10) | YES | | NULL | | | name | varchar(10) | YES | MUL | NULL | | | cardid | int(18) | YES | MUL | NULL | | | phone | int(11) | YES | | NULL | | | address | varchar(50) | YES | | NULL | | | remark | text | YES | | NULL | | +---------+-------------+------+-----+---------+-------+ 6 rows in set (0.00 sec)③創建表的時候指定索引
create table 表名 (字段1 數據類型,字段2 數據類型[,...],index (列名));
mysql> create table test (id int,name varchar(10),index name_index (name)); Query OK, 0 rows affected (0.01 sec)mysql> desc test; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | name | varchar(10) | YES | MUL | NULL | | +-------+-------------+------+-----+---------+-------+ 2 rows in set (0.00 sec)(2)唯一索引
唯一索引:與普通索引類似,但區別是唯一索引列的每個值都唯一。唯一索引允許有空值(注意和主鍵不同)。如果是用組合索引創建,則列值的組合必須唯一。添加唯一鍵將自動創建唯一索引。
①直接創建唯一索引
create unique index 索引名 on 表名(列名);
mysql> create unique index phone_index on member(phone); Query OK, 0 rows affected (0.01 sec) Records: 0 Duplicates: 0 Warnings: 0mysql> desc member; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | id | int(10) | YES | | NULL | | | name | varchar(10) | YES | MUL | NULL | | | cardid | int(18) | YES | MUL | NULL | | | phone | int(11) | YES | UNI | NULL | | | address | varchar(50) | YES | | NULL | | | remark | text | YES | | NULL | | +---------+-------------+------+-----+---------+-------+ 6 rows in set (0.00 sec)②修改表方式創建
alter table 表名 add unique 索引名 (列名);
mysql> alter table member add unique add_index (address); Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0mysql> desc member; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | id | int(10) | YES | | NULL | | | name | varchar(10) | YES | MUL | NULL | | | cardid | int(18) | YES | MUL | NULL | | | phone | int(11) | YES | UNI | NULL | | | address | varchar(50) | YES | UNI | NULL | | | remark | text | YES | | NULL | | +---------+-------------+------+-----+---------+-------+ 6 rows in set (0.00 sec)③創建表的時候指定
create table 表名 (字段1 數據類型,字段2 數據類型[,...],unique 索引名 (列名));
mysql> create table test (id int,name varchar(10),cardid bigint(18),unique cardid_index (cardid)); Query OK, 0 rows affected (0.00 sec)mysql> desc test; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | name | varchar(10) | YES | | NULL | | | cardid | bigint(18) | YES | UNI | NULL | | +--------+-------------+------+-----+---------+-------+ 3 rows in set (0.00 sec)(3)主鍵索引
主鍵索引:是一種特殊的唯一索引,必須指定為"primary key"。一個表只能有一個主鍵索引,不允許有空值。添加主鍵將自動創建主鍵索引。
①創建表的時候指定
create table 表名 ([...],primary key (列名));
mysql> create table test (id int,name varchar(10),primary key(id)); Query OK, 0 rows affected (0.01 sec)mysql> desc test; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | id | int(11) | NO | PRI | NULL | | | name | varchar(10) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 2 rows in set (0.00 sec)②修改表方式創建
alter table 表名 add primary key (列名);
mysql> alter table member add primary key (id); Query OK, 0 rows affected (0.06 sec) Records: 0 Duplicates: 0 Warnings: 0mysql> desc member; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | id | int(10) | NO | PRI | NULL | | | name | varchar(10) | YES | MUL | NULL | | | cardid | int(18) | YES | MUL | NULL | | | phone | int(11) | YES | UNI | NULL | | | address | varchar(50) | YES | UNI | NULL | | | remark | text | YES | | NULL | | +---------+-------------+------+-----+---------+-------+ 6 rows in set (0.01 sec)(4)組合索引
組合索引(單列索引與多列索引):可以是單列上創建的索引,也可以是在多列上創建的所有。需要滿足最左原則,因為select語句的where條件是依次從左往右執行的,所以在使用select語句查詢時where條件使用的字段順序必須和組合索引中的排序一直,否則索引將不會生效。
①創建:
create table 表名 (列名1 數據類型,列名2 數據類型,列名3 數據類型,index 索引名 (列名1,列名2,列名3));
mysql> create table menu (id int,foodname varchar(20),price int,index foodprice_index (id,foodname,price)); Query OK, 0 rows affected (0.00 sec)mysql> desc menu; +----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+-------------+------+-----+---------+-------+ | id | int(11) | YES | MUL | NULL | | | foodname | varchar(20) | YES | | NULL | | | price | int(11) | YES | | NULL | | +----------+-------------+------+-----+---------+-------+ 3 rows in set (0.00 sec)mysql> show create table menu; +-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | menu | CREATE TABLE "menu" ("id" int(11) DEFAULT NULL,"foodname" varchar(20) DEFAULT NULL,"price" int(11) DEFAULT NULL,KEY "foodprice_index" ("id","foodname","price") ) ENGINE=InnoDB DEFAULT CHARSET=utf8 | +-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)②查詢:
select * from 表名 where 列名1='...' and 列名2='...' and 列名3='...';
mysql> insert into menu values(1,'魚香肉絲',28); Query OK, 1 row affected (0.00 sec)mysql> insert into menu values(2,'麻婆豆腐',18); Query OK, 1 row affected (0.00 sec)mysql> insert into menu values(3,'水煮肉片',38); Query OK, 1 row affected (0.00 sec)mysql> insert into menu values(4,'辣子雞',38); Query OK, 1 row affected (0.00 sec)mysql> select * from menu; +------+--------------+-------+ | id | foodname | price | +------+--------------+-------+ | 1 | 魚香肉絲 | 28 | | 2 | 麻婆豆腐 | 18 | | 3 | 水煮肉片 | 38 | | 4 | 辣子雞 | 38 | +------+--------------+-------+ 4 rows in set (0.00 sec)mysql> select * from menu where price=38 and foodname='辣子雞'; +------+-----------+-------+ | id | foodname | price | +------+-----------+-------+ | 4 | 辣子雞 | 38 | +------+-----------+-------+ 1 row in set (0.00 sec)mysql> select * from menu where price=38 and id=3; +------+--------------+-------+ | id | foodname | price | +------+--------------+-------+ | 3 | 水煮肉片 | 38 | +------+--------------+-------+ 1 row in set (0.00 sec)(5)全文索引
全文索引(fulltext):適合在進行模糊查詢的時候使用,可用于在一篇文章中檢索文本信息。在MySQL5.6版本以前,fulltext索引僅可用于MyISAM引擎,在5.6版本之后innodb引擎也支持fulltext索引。全文索引可以在char、varchar或者text類型的列上創建。每個表只允許有一個全文索引。
①直接創建索引
create fulltext index 索引名 on 表名 (列名);
mysql> create fulltext index remark_index on member (remark); Query OK, 0 rows affected, 1 warning (0.02 sec) Records: 0 Duplicates: 0 Warnings: 1mysql> desc member; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | id | int(10) | NO | PRI | NULL | | | name | varchar(10) | YES | MUL | NULL | | | cardid | int(18) | YES | MUL | NULL | | | phone | int(11) | YES | UNI | NULL | | | address | varchar(50) | YES | UNI | NULL | | | remark | text | YES | MUL | NULL | | +---------+-------------+------+-----+---------+-------+ 6 rows in set (0.00 sec)mysql> show create table member; +--------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +--------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | member | CREATE TABLE "member" ("id" int(10) NOT NULL,"name" varchar(10) DEFAULT NULL,"cardid" int(18) DEFAULT NULL,"phone" int(11) DEFAULT NULL,"address" varchar(50) DEFAULT NULL,"remark" text,PRIMARY KEY ("id"),UNIQUE KEY "phone_index" ("phone"),UNIQUE KEY "add_index" ("address"),KEY "name_index" ("name"),KEY "cardid_index" ("cardid"),FULLTEXT KEY "remark_index" ("remark") ) ENGINE=InnoDB DEFAULT CHARSET=utf8 | +--------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)②修改表方式創建
alter table 表名 add fulltext 索引名 (列名);
mysql> drop index remark_index on member; Query OK, 0 rows affected (0.01 sec) Records: 0 Duplicates: 0 Warnings: 0mysql> desc member; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | id | int(10) | NO | PRI | NULL | | | name | varchar(10) | YES | MUL | NULL | | | cardid | int(18) | YES | MUL | NULL | | | phone | int(11) | YES | UNI | NULL | | | address | varchar(50) | YES | UNI | NULL | | | remark | text | YES | | NULL | | +---------+-------------+------+-----+---------+-------+ 6 rows in set (0.00 sec)mysql> alter table member add fulltext remark_index (remark); Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0mysql> desc member; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | id | int(10) | NO | PRI | NULL | | | name | varchar(10) | YES | MUL | NULL | | | cardid | int(18) | YES | MUL | NULL | | | phone | int(11) | YES | UNI | NULL | | | address | varchar(50) | YES | UNI | NULL | | | remark | text | YES | MUL | NULL | | +---------+-------------+------+-----+---------+-------+ 6 rows in set (0.00 sec)③創建表的時候指定索引
create table 表名 (字段1 數據類型[,...],fulltext 索引名 (列名));
數據類型只可為char、varchar、text。
④使用全文索引查詢
select * from 表名 where match(列名) against('查詢內容');
mysql> insert into staff_info values (1,'zhangsan',112233445566778899,23,13111111111,'this is chairman'); Query OK, 1 row affected (0.00 sec)mysql> insert into staff_info values (2,'lisi',212233445566778899,33,13222222222,'this is ceo'); Query OK, 1 row affected (0.00 sec)mysql> insert into staff_info values (3,'wangwu',312233445566778899,43,13333333333,'this is cfo'); Query OK, 1 row affected (0.00 sec)mysql> insert into staff_info values (4,'zhaoliu',412233445566778899,44,13444444444,'this is hr'); Query OK, 1 row affected (0.00 sec)mysql> select * from staff_info; +------+----------+--------------------+------+-------------+------------------+ | id | name | cardid | age | phone | remark | +------+----------+--------------------+------+-------------+------------------+ | 1 | zhangsan | 112233445566778899 | 23 | 13111111111 | this is chairman | | 2 | lisi | 212233445566778899 | 33 | 13222222222 | this is ceo | | 3 | wangwu | 312233445566778899 | 43 | 13333333333 | this is cfo | | 4 | zhaoliu | 412233445566778899 | 44 | 13444444444 | this is hr | +------+----------+--------------------+------+-------------+------------------+ 4 rows in set (0.00 sec)mysql> mysql> select * from staff_info whereremark) against('ceo'); +------+------+--------------------+------+-------------+-------------+ | id | name | cardid | age | phone | remark | +------+------+--------------------+------+-------------+-------------+ | 2 | lisi | 212233445566778899 | 33 | 13222222222 | this is ceo | +------+------+--------------------+------+-------------+-------------+ 1 row in set (0.00 sec)6. 查看索引
show index from 表名;
show keys from 表名;
一般建議使用\G縱向查看
show index from 表名\G;
show keys from 表名\G;
7. 刪除索引
(1)直接刪除索引
drop index 索引名 on 表名;
mysql> drop index name_index on member; Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0mysql> desc member; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | id | int(10) | NO | PRI | NULL | | | name | varchar(10) | YES | | NULL | | | cardid | int(18) | YES | MUL | NULL | | | phone | int(11) | YES | UNI | NULL | | | address | varchar(50) | YES | UNI | NULL | | | remark | text | YES | MUL | NULL | | +---------+-------------+------+-----+---------+-------+ 6 rows in set (0.00 sec)(2)修改表方式刪除索引
alter table 表名 drop index 索引名;
mysql> alter table member drop index cardid_index; Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0mysql> desc member; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | id | int(10) | NO | PRI | NULL | | | name | varchar(10) | YES | | NULL | | | cardid | int(18) | YES | | NULL | | | phone | int(11) | YES | UNI | NULL | | | address | varchar(50) | YES | UNI | NULL | | | remark | text | YES | MUL | NULL | | +---------+-------------+------+-----+---------+-------+ 6 rows in set (0.00 sec)(3)刪除主鍵索引
alter table 表名 drop primary key;
mysql> alter table member drop primary key; Query OK, 0 rows affected (0.03 sec) Records: 0 Duplicates: 0 Warnings: 0mysql> desc member; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | id | int(10) | NO | | NULL | | | name | varchar(10) | YES | | NULL | | | cardid | int(18) | YES | | NULL | | | phone | int(11) | YES | UNI | NULL | | | address | varchar(50) | YES | UNI | NULL | | | remark | text | YES | MUL | NULL | | +---------+-------------+------+-----+---------+-------+ 6 rows in set (0.00 sec)8. 案例
比如為某商場做一個會員卡系統。這個系統有一個會員表,有下列字段:
● 會員編號 int(10)
作為主鍵,使用primary key
● 會員姓名 varchar(10)
建立普通索引
● 會員身份證號碼 varchar(18)
建立唯一索引
● 會員電話 bigint(11)
● 會員住址 varchar(50)
● 會員備注信息 text
建立fulltext,全文索引。不過fulltext用于搜索很長一篇文章的時候,效果最好。用在比較短的文本,如果就一兩行字的,普通的index也可以
總結
MySQL部分都很重要,要好好學
總結
以上是生活随笔為你收集整理的MySQL数据库授权与索引的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 人物-丁磊:丁磊
- 下一篇: python气象学_Python气象绘图