中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

簡單理解MySQL索引視圖事務,存儲引擎MyLSAM和InnoDB相關知識

發布時間:2020-05-11 09:59:43 來源:億速云 閱讀:286 作者:三月 欄目:系統運維

本文主要給大家簡單講講MySQL索引視圖事務,存儲引擎MyLSAM和InnoDB相關知識,相關專業術語大家可以上網查查或者找一些相關書籍補充一下,這里就不涉獵了,我們就直奔主題吧,希望MySQL索引視圖事務,存儲引擎MyLSAM和InnoDB相關知識這篇文章可以給大家帶來一些實際幫助。

索引的作用

設置了合適的索引之后,數據庫利用各種快速的定位技術,能夠大大加快查詢速率;
特別是當表很大時,或者查詢涉及到多個表時,使用索引可使查詢加快成千倍;
可以降低數據庫的IO成本,并且索引還可以降低數據庫的排序成本;
通過創建唯一性索引保證數據表數據的唯一性;
可以加快表與表之間的連接;
在使用分組和排序時,可大大減少分組和排序時間;

1,進入數據庫,創建數據庫,創建表

[root@master2 ~]# mysql -uroot -p     ##進入數據庫
Enter password:     ##輸入密碼

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database school;    ##創建數據庫school
Query OK, 1 row affected (0.00 sec)

mysql> use school;       ##使用數據庫
Database changed
mysql> create table info(        ##創建表
        -> id int(4) not null primary key auto_increment,   ##設置主鍵,自動增加
        -> name varchar(10) not null,       ##名字類型varchar不為空
        -> address varchar(50) default 'nanjing',    ##默認南京
        -> age int(3) not null);
Query OK, 0 rows affected (0.02 sec)

2,向表中插入數據

簡單理解MySQL索引視圖事務,存儲引擎MyLSAM和InnoDB相關知識

mysql> insert into info (name,address,age) values ('zhangsan','beijing',20),('lisi','shanghai',22); 
##插入數據
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select * from info;   ##查看表內容
+----+----------+----------+-----+
| id | name     | address  | age |
+----+----------+----------+-----+
|  1 | zhangsan | beijing  |  20 |
|  2 | lisi     | shanghai |  22 |
+----+----------+----------+-----+
2 rows in set (0.00 sec)

mysql> desc info;               ##查看表結構
+---------+-------------+------+-----+---------+----------------+
| Field   | Type        | Null | Key | Default | Extra          |
+---------+-------------+------+-----+---------+----------------+
| id      | int(4)      | NO   | PRI | NULL    | auto_increment |
| name    | varchar(10) | NO   |     | NULL    |                |
| address | varchar(50) | YES  |     | nanjing |                |
| age     | int(3)      | NO   |     | NULL    |                |
+---------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

3,使用create,alter,創建表直接定義三種方式創建索引(普通索引,唯一性索引)

mysql> create index index_age on info (age);   ##創建普通索引
Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show index from info;   ##查看表中的索引
+-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name  | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| info  |          0 | PRIMARY   |            1 | id          | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
| info  |          1 | index_age |            1 | age         | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
+-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
2 rows in set (0.00 sec)

mysql> drop index index_age on info;   ##刪除表中的索引
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show index from info;        ##查看表中的索引         
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| info  |          0 | PRIMARY  |            1 | id          | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
1 row in set (0.01 sec)

mysql> create unique index unique_name on info (name); ##創建唯一性索引
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show index from info;  ##查看表中索引
+-------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name    | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| info  |          0 | PRIMARY     |            1 | id          | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
| info  |          0 | unique_name |            1 | name        | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
+-------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
2 rows in set (0.00 sec)

mysql> drop index unique_name on info;  ##刪除表中的索引
Query OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show index from info;          ##查看表中的索引
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| info  |          0 | PRIMARY  |            1 | id          | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
1 row in set (0.00 sec)

mysql> alter table info add unique index index_name (name);   ##使用alter插入表索引
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show index from info;   ##查看表中的索引
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name   | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| info  |          0 | PRIMARY    |            1 | id          | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
| info  |          0 | index_name |            1 | name        | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
2 rows in set (0.00 sec)

4,創建兩個表,進行關聯,多表查詢

mysql> create table user(     ##創建user表
        -> id int(4) not null primary key auto_increment,   ##設置主鍵和自動增加
        -> name varchar(10) not null,
        -> score decimal not null,
        -> hobby int(2) not null default '1',  ##默認1
        -> index index_score (score));    ##設置索引score
Query OK, 0 rows affected (0.01 sec)

mysql> desc user;  ##查看表結構
+-------+---------------+------+-----+---------+----------------+
| Field | Type          | Null | Key | Default | Extra          |
+-------+---------------+------+-----+---------+----------------+
| id    | int(4)        | NO   | PRI | NULL    | auto_increment |
| name  | varchar(10)   | NO   |     | NULL    |                |
| score | decimal(10,0) | NO   | MUL | NULL    |                |
| hobby | int(2)        | NO   |     | 1       |                |
+-------+---------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

mysql> insert into user (name,score,hobby) values ('test01',88,1),('stu01',99,2),('wangwu',77,3); 
##向表中插入數據
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from user;    ##查看表內容
+----+--------+-------+-------+
| id | name   | score | hobby |
+----+--------+-------+-------+
|  1 | test01 |    88 |     1 |
|  2 | stu01  |    99 |     2 |
|  3 | wangwu |    77 |     3 |
+----+--------+-------+-------+
3 rows in set (0.00 sec)

mysql> create table hob(     ##創建hob表
        -> id int(2) not null primary key,
        -> hob_name varchar(10) not null);
Query OK, 0 rows affected (0.00 sec)

mysql> desc hob;   ##查看表結構
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id       | int(2)      | NO   | PRI | NULL    |       |
| hob_name | varchar(10) | NO   |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> insert into hob (id,hob_name) values (1,'看書'),(2,'運動'),(3,'聽歌');   ##插入表數據
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from hob;   ##查看表內容
+----+----------+
| id | hob_name |
+----+----------+
|  1 | 看書     |
|  2 | 運動     |
|  3 | 聽歌     |
+----+----------+
3 rows in set (0.00 sec)

mysql> select * from user inner join hob on user.hobby=hob.id;   ##關聯user和hob兩張表
+----+--------+-------+-------+----+----------+
| id | name   | score | hobby | id | hob_name |
+----+--------+-------+-------+----+----------+
|  1 | test01 |    88 |     1 |  1 | 看書     |
|  2 | stu01  |    99 |     2 |  2 | 運動     |
|  3 | wangwu |    77 |     3 |  3 | 聽歌     |
+----+--------+-------+-------+----+----------+
3 rows in set (0.00 sec)

mysql> select user.name,hob.hob_name from user inner join hob on user.hobby=hob.id;
##去除其他內容顯示name和hob_name內容
+--------+----------+
| name   | hob_name |
+--------+----------+
| test01 | 看書     |
| stu01  | 運動     |
| wangwu | 聽歌     |
+--------+----------+
3 rows in set (0.00 sec)

mysql> select u.name,h.hob_name from user u inner join hob h on u.hobby=h.id; ##設置簡易名稱
+--------+----------+
| name   | hob_name |
+--------+----------+
| test01 | 看書     |
| stu01  | 運動     |
| wangwu | 聽歌     |
+--------+----------+
3 rows in set (0.00 sec)

mysql> create view view_user as select u.name,h.hob_name from user u inner join hob h on u.hobby
##創建視圖
Query OK, 0 rows affected (0.00 sec)

mysql> select * from view_user;  ##查看視圖
+--------+----------+
| name   | hob_name |
+--------+----------+
| test01 | 看書     |
| stu01  | 運動     |
| wangwu | 聽歌     |
+--------+----------+
3 rows in set (0.00 sec)

mysql> update user set hobby=3 where name='test01';  ##修改user表中內容
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from view_user;   ##查看視圖,即視圖就是表的一個鏈接
+--------+----------+
| name   | hob_name |
+--------+----------+
| stu01  | 運動     |
| test01 | 聽歌     |
| wangwu | 聽歌     |
+--------+----------+
3 rows in set (0.00 sec)

5,全文索引,組合索引

mysql> select * from info;     ##查看表內容
+----+----------+----------+-----+
| id | name     | address  | age |
+----+----------+----------+-----+
|  1 | zhangsan | beijing  |  20 |
|  2 | lisi     | shanghai |  22 |
+----+----------+----------+-----+
2 rows in set (0.00 sec)

mysql> show index from info;    ##查看表的索引
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name   | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| info  |          0 | PRIMARY    |            1 | id          | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
| info  |          0 | index_name |            1 | name        | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
2 rows in set (0.00 sec)

mysql> create fulltext index full_addr on info (address);      ##以address創建全文索引
Query OK, 0 rows affected, 1 warning (0.07 sec)
Records: 0  Duplicates: 0  Warnings: 1

mysql> show index from info;  ##查看表索引
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name   | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| info  |          0 | PRIMARY    |            1 | id          | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
| info  |          0 | index_name |            1 | name        | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
| info  |          1 | full_addr  |            1 | address     | NULL      |           2 |     NULL | NULL   | YES  | FULLTEXT   |         |               |
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
3 rows in set (0.00 sec)

mysql> select * from user;     ##查看user表內容
+----+--------+-------+-------+
| id | name   | score | hobby |
+----+--------+-------+-------+
|  1 | test01 |    88 |     3 |
|  2 | stu01  |    99 |     2 |
|  3 | wangwu |    77 |     3 |
+----+--------+-------+-------+
3 rows in set (0.00 sec)

mysql> create index index_name_score on user (name,score);    ##創建name和score的組合索引
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show index from user;   ##查看表索引
+-------+------------+------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name         | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| user  |          0 | PRIMARY          |            1 | id          | A         |           3 |     NULL | NULL   |      | BTREE      |         |               |
| user  |          1 | index_score      |            1 | score       | A         |           3 |     NULL | NULL   |      | BTREE      |         |               |
| user  |          1 | index_name_score |            1 | name        | A         |           3 |     NULL | NULL   |      | BTREE      |         |               |
| user  |          1 | index_name_score |            2 | score       | A         |           3 |     NULL | NULL   |      | BTREE      |         |               |
+-------+------------+------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
4 rows in set (0.00 sec)

事務的特點

原子性:
事務是一個完整的操作,事務的各元素是不可分的(原子的)
事務中的所有元素必須作為一個整體提交或回滾
如果事務中的任何元素失敗,則整個事務將失敗
一致性:
當事務完成時,數據必須處于一致狀態:在事務開始之前,數據庫中存儲的數據處于一致狀態;在正在進行的事務中,數據可能處于不一致的狀態;當事務成功完成時,數據必須再次回到已知的一致狀態
隔離性:
對數據進行修改的所有并發事務是彼此隔離的,這表明事務必須是獨立的,他不應以任何方式依賴于或影響其他事務
修改數據的事務可以在另一個使用相同數據的事務開始之前訪問這些數據,或者再另一個使用相同的數據的事務結束之后訪問這些數據
持久性:
事務持久性指不管系統是否發生故障,事務處理的結果都是永久的
一旦事務被提交,事務的效果會被永久的保留在數據庫中

1,開啟事務,往表中插入數據

mysql> select * from info;   ##查看表內容數據
+----+----------+----------+-----+
| id | name     | address  | age |
+----+----------+----------+-----+
|  1 | zhangsan | beijing  |  20 |
|  2 | lisi     | shanghai |  22 |
+----+----------+----------+-----+
2 rows in set (0.00 sec)

mysql> insert into info (name,address,age) values ('wangwu','hangzhou',30);##插入數據

mysql> begin;   ##開啟事務
Query OK, 0 rows affected (0.00 sec)

mysql> insert into info (name,address,age) values ('zhaoliu','hangzhou',31);  ##插入數據
Query OK, 1 row affected (0.00 sec)

mysql> savepoint a;   ##設置保存節點a
Query OK, 0 rows affected (0.00 sec)

mysql> select * from info;   ##查看表數據
+----+----------+----------+-----+
| id | name     | address  | age |
+----+----------+----------+-----+
|  1 | zhangsan | beijing  |  20 |
|  2 | lisi     | shanghai |  22 |
|  3 | wangwu   | hangzhou |  30 |
|  4 | zhaoliu  | hangzhou |  31 |
+----+----------+----------+-----+
4 rows in set (0.00 sec)

mysql> insert into info (name,address,age) values ('tianqi','hangzhou',32);  ##繼續插入數據
Query OK, 1 row affected (0.00 sec)

mysql> savepoint b;   ##設置保存節點b
Query OK, 0 rows affected (0.00 sec)

mysql> insert into info (name,address,age) values ('heiba','hangzhou',32);      ##繼續插入數據
Query OK, 1 row affected (0.00 sec)

mysql> select * from info;  ##查看表內容
+----+----------+----------+-----+
| id | name     | address  | age |
+----+----------+----------+-----+
|  1 | zhangsan | beijing  |  20 |
|  2 | lisi     | shanghai |  22 |
|  3 | wangwu   | hangzhou |  30 |
|  4 | zhaoliu  | hangzhou |  31 |
|  5 | tianqi   | hangzhou |  32 |
|  6 | heiba    | hangzhou |  32 |
+----+----------+----------+-----+
6 rows in set (0.00 sec)

2,利用另一個終端查看是否成功插入

[root@master2 ~]# mysql -uroot -p  ##進入數據庫
Enter password:     ##輸入密碼

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use school;   ##使用數據庫
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from info;   ##查看表內容,此時并沒有提交
+----+----------+----------+-----+
| id | name     | address  | age |
+----+----------+----------+-----+
|  1 | zhangsan | beijing  |  20 |
|  2 | lisi     | shanghai |  22 |
|  3 | wangwu   | hangzhou |  30 |
+----+----------+----------+-----+
3 rows in set (0.00 sec)

3,使用回滾,返回保存的節點

mysql> rollback to b;    ##利用回滾到保存節點b
Query OK, 0 rows affected (0.00 sec)

mysql> select * from info;   ##查看表數據
+----+----------+----------+-----+
| id | name     | address  | age |
+----+----------+----------+-----+
|  1 | zhangsan | beijing  |  20 |
|  2 | lisi     | shanghai |  22 |
|  3 | wangwu   | hangzhou |  30 |
|  4 | zhaoliu  | hangzhou |  31 |
|  5 | tianqi   | hangzhou |  32 |
+----+----------+----------+-----+
5 rows in set (0.00 sec)

mysql> rollback to a;  ##回滾到保存節點a
Query OK, 0 rows affected (0.00 sec)

mysql> select * from info;   ##查看表數據
+----+----------+----------+-----+
| id | name     | address  | age |
+----+----------+----------+-----+
|  1 | zhangsan | beijing  |  20 |
|  2 | lisi     | shanghai |  22 |
|  3 | wangwu   | hangzhou |  30 |
|  4 | zhaoliu  | hangzhou |  31 |
+----+----------+----------+-----+
4 rows in set (0.00 sec)

mysql> rollback;     ##回滾到初始,退出事務狀態
Query OK, 0 rows affected (0.00 sec)

mysql> select * from info;  ##查看表數據
+----+----------+----------+-----+
| id | name     | address  | age |
+----+----------+----------+-----+
|  1 | zhangsan | beijing  |  20 |
|  2 | lisi     | shanghai |  22 |
|  3 | wangwu   | hangzhou |  30 |
+----+----------+----------+-----+
3 rows in set (0.00 sec)

4,使用commit提交事務

mysql> begin;    ##開啟事務
Query OK, 0 rows affected (0.00 sec)

mysql> insert into info (name,address,age) values ('heiba','hangzhou',32);  ##插入數據
Query OK, 1 row affected (0.00 sec)

mysql> commit;   ##提交事務
Query OK, 0 rows affected (0.00 sec)

mysql> select * from info;  ##查看表數據
+----+----------+----------+-----+
| id | name     | address  | age |
+----+----------+----------+-----+
|  1 | zhangsan | beijing  |  20 |
|  2 | lisi     | shanghai |  22 |
|  3 | wangwu   | hangzhou |  30 |
|  7 | heiba    | hangzhou |  32 |
+----+----------+----------+-----+
4 rows in set (0.00 sec)

5,使用另一個終端查看

mysql> select * from info;   ##查看表數據
+----+----------+----------+-----+
| id | name     | address  | age |
+----+----------+----------+-----+
|  1 | zhangsan | beijing  |  20 |
|  2 | lisi     | shanghai |  22 |
|  3 | wangwu   | hangzhou |  30 |
|  7 | heiba    | hangzhou |  32 |
+----+----------+----------+-----+
4 rows in set (0.00 sec)

6,另一種事務的操作方式

mysql> set autocommit=0;   ##設置不自動提交事務
Query OK, 0 rows affected (0.00 sec)

mysql> update info set address='beijing' where name='heiba';  ##修改表數據
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from info;   ##查看表信息
+----+----------+----------+-----+
| id | name     | address  | age |
+----+----------+----------+-----+
|  1 | zhangsan | beijing  |  20 |
|  2 | lisi     | shanghai |  22 |
|  3 | wangwu   | hangzhou |  30 |
|  7 | heiba    | beijing  |  32 |
+----+----------+----------+-----+
4 rows in set (0.00 sec)

##另一個終端查看
mysql> select * from info;  ##查看表信息,并沒有修改
+----+----------+----------+-----+
| id | name     | address  | age |
+----+----------+----------+-----+
|  1 | zhangsan | beijing  |  20 |
|  2 | lisi     | shanghai |  22 |
|  3 | wangwu   | hangzhou |  30 |
|  7 | heiba    | hangzhou |  32 |
+----+----------+----------+-----+
4 rows in set (0.00 sec)

mysql> set autocommit=1;   ##開啟自動提交事務
Query OK, 0 rows affected (0.00 sec)

##另一個終端查看
mysql> select * from info;   ##查看表數據,此時就已經修改
+----+----------+----------+-----+
| id | name     | address  | age |
+----+----------+----------+-----+
|  1 | zhangsan | beijing  |  20 |
|  2 | lisi     | shanghai |  22 |
|  3 | wangwu   | hangzhou |  30 |
|  7 | heiba    | beijing  |  32 |
+----+----------+----------+-----+
4 rows in set (0.00 sec)

存儲引擎MyLSAM和InnoDB

1,查看系統默認存儲引擎

mysql> show engines;   ##查看默認存儲引擎innodb
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |

mysql> show create table info;   ##查看創建的表的存儲引擎innodb

| info  | CREATE TABLE "info" (
    "id" int(4) NOT NULL AUTO_INCREMENT,
    "name" varchar(10) NOT NULL,
    "address" varchar(50) DEFAULT 'nanjing',
    "age" int(3) NOT NULL,
    PRIMARY KEY ("id"),
    UNIQUE KEY "index_name" ("name"),
    FULLTEXT KEY "full_addr" ("address")
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8

2,修改MySQL配置文件,設置默認的存儲引擎

[root@localhost ~]# vim /etc/my.cnf ##修改配置文件

[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysql.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
default-storage-engine=Myisam   ##添加默認存儲引擎為Myisam

[root@master2 ~]# systemctl restart mysqld.service ##重啟MySQL服務

3,進入數據庫

[root@master2 ~]# mysql -uroot -p   ##進入數據庫
Enter password:    ##輸入密碼

mysql> use school;    ##使用數據庫
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> create table a ( id int );    ##創建一個a表
Query OK, 0 rows affected (0.00 sec)

mysql> show create table a;   ##查看表默認的存儲引擎Myisam
+-------+-------------------------------------------------------------------------------------+
| Table | Create Table                                                                        |
+-------+-------------------------------------------------------------------------------------+
| a     | CREATE TABLE "a" (
    "id" int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+-------+-------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> alter table a engine=innodb;  ##修改表的存儲引擎為innodb
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show create table a;  ##查看表的存儲引擎innodb
+-------+-------------------------------------------------------------------------------------+
| Table | Create Table                                                                        |
+-------+-------------------------------------------------------------------------------------+
| a     | CREATE TABLE "a" (
    "id" int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+-------------------------------------------------------------------------------------+

1 row in set (0.00 sec)

MySQL索引視圖事務,存儲引擎MyLSAM和InnoDB相關知識就先給大家講到這里,對于其它相關問題大家想要了解的可以持續關注我們的行業資訊。我們的板塊內容每天都會捕捉一些行業新聞及專業知識分享給大家的。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

元氏县| 宜兰市| 皋兰县| 孝昌县| 茌平县| 建德市| 都兰县| 桂林市| 大安市| 卢龙县| 宿州市| 格尔木市| 上高县| 新竹县| 繁昌县| 同心县| 和平区| 石台县| 新郑市| 衡山县| 海丰县| 竹山县| 巴东县| 南靖县| 巴彦淖尔市| 紫金县| 会昌县| 平乡县| 南开区| 蒙山县| 黑龙江省| 邢台市| 耿马| 宁陕县| 修水县| 高平市| 安宁市| 乌拉特前旗| 六盘水市| 张家口市| 德安县|