1. 程式人生 > 實用技巧 >mysql innodb儲存引擎的表空間

mysql innodb儲存引擎的表空間

InnoDB儲存引擎的表空間

1.共享表空間(ibdata1)

1)儲存的內容

1.系統資料
2.臨時表
3.undo 日誌		事務的日誌 redo undo

2)檢視共享表空間

mysql> show variables like '%path%';
+-----------------------+------------------------+
| Variable_name         | Value                  |
+-----------------------+------------------------+
| innodb_data_file_path | ibdata1:12M:autoextend |
| ssl_capath            |                        |
| ssl_crlpath           |                        |
+-----------------------+------------------------+
3 rows in set (0.00 sec)

3)配置共享表空間

#1.編輯配置檔案
[root@db01 ~]# vim /etc/my.cnf
[mysqld]
innodb_data_file_path=ibdata1:50M;ibdata2:50M:autoextend

#2.啟動資料庫報錯
[root@db01 ~]# systemctl restart mysqld.service
#為了檢視報錯
[root@db01 ~]# /etc/init.d/mysqld start
Starting MySQL. ERROR! The server quit without updating PID file (/usr/local/mysql/data/db01.pid).

#3.看日誌報錯
[root@db01 ~]# less /usr/local/mysql/data/db01.err
2020-10-29 18:10:47 16917 [ERROR] InnoDB: Data file ./ibdata1 is of a different size 4864 pages (rounded down to MB) than specified in the .cnf file 768 pages!

#4.錯誤原因
共享表空間ibdata1設定的結束大小與實際ibdata1大小不符合

#5.解決問題
[root@db01 ~]# vim /etc/my.cnf
[mysqld]
#修改ibdata1大小與資料目錄下的大小一致即可
innodb_data_file_path=ibdata1:76M;ibdata2:12M:autoextend

#6.重啟服務
[root@db01 ~]# systemctl restart mysqld.service

2.獨立表空間

1)檢視獨立表空間

#1.物理層面檢視
[root@db01 ~]# ll /usr/local/mysql/data/xiangqin
總用量 144
-rw-rw---- 1 mysql mysql   8785 10月 28 19:05 user.frm
-rw-rw---- 1 mysql mysql 131072 10月 28 19:05 user.ibd

#2.資料庫檢視
mysql> show variables like '%per_table%';
+-----------------------+-------+
| Variable_name         | Value |
+-----------------------+-------+
| innodb_file_per_table | ON    |
+-----------------------+-------+
1 row in set (0.00 sec)