MySQL 8.0 Reference Manual(讀書筆記69節--InnoDB Startup Configuration)

来源:https://www.cnblogs.com/xuliuzai/p/18091743
-Advertisement-
Play Games

增 增加單條數據 insert into Department(DepartmentName,DepartmentDesc) values('研發部','這是研發部')--插入單條數據 多條 /*insert into [Rank](RankName,RankDesc) select 'A','A級 ...


1.配置文件化

有些InnoDB的配置,是在實例初始化時,就決定了,所以,建議寫在configuration file 文件中。

Because MySQL uses data file, log file, and page size settings to initialize InnoDB, it is recommended that you define these settings in an option file that MySQL reads at startup, prior to initializing InnoDB. Normally, InnoDB is initialized when the MySQL server is started for the first time.

一般都放在[mysqld]屬性組裡面

You can place InnoDB options in the [mysqld] group of any option file that your server reads when it starts.

2.一些關於【存儲】相關的重要參數

Review the following storage-related considerations before proceeding with your startup configuration.

• In some cases, you can improve database performance by placing data and log files on separate physical disks. You can also use raw disk partitions (raw devices) for InnoDB data files, which may speed up I/O.

• InnoDB is a transaction-safe (ACID compliant) storage engine with commit, rollback, and crash-recovery capabilities to protect user data. However, it cannot do so if the underlying【下層的,作為基礎的】 operating system or hardware does not work as advertised【廣告上的;宣傳的】. Many operating systems or disk subsystems may delay or reorder【重新排列;重新佈置】 write operations to improve performance. On some operating systems, the very fsync() system call that should wait until all unwritten data for a file has been flushed might actually return before the data has been flushed to stable storage. Because of this, an operating system crash or a power outage may destroy recently committed data, or in the worst case, even corrupt the database because write operations have been reordered. If data integrity is important to you, perform “pull-the-plug” tests before using anything in production. On macOS, InnoDB uses a special fcntl() file flush method. Under Linux, it is advisable to disable the write-back cache.

On ATA/SATA disk drives, a command such hdparm -W0 /dev/hda may work to disable the writeback cache. Beware that some drives or disk controllers may be unable to disable the write-back cache.

• With regard to InnoDB recovery capabilities that protect user data, InnoDB uses a file flush technique involving a structure called the doublewrite buffer, which is enabled by default (innodb_doublewrite=ON). The doublewrite buffer adds safety to recovery following an unexpected exit or power outage, and improves performance on most varieties of Unix by reducing the need for fsync() operations. It is recommended that the innodb_doublewrite option remains enabled if you are concerned with data integrity or possible failures.--- 強調innodb_doublewrite重要性

 3.系統表空間配置

The innodb_data_file_path option defines the name, size, and attributes of InnoDB system tablespace data files. If you do not configure this option prior to initializing the MySQL server, the default behavior is to create a single auto-extending data file, slightly larger than 12MB, named ibdata1:ibdata1:12M:autoextend

You can specify more than one data file using a semicolon-separated【用分號隔開】 list.例如:innodb_data_file_path=ibdata1:50M;ibdata2:50M:autoextend

The autoextend and max attributes can be used only for the data file that is specified last.--可以設置最大值。To specify a maximum size for an auto-extending data file, use the max attribute following the autoextend attribute. Use the max attribute only in cases where constraining disk usage is of critical importance. The following configuration permits ibdata1 to grow to a limit of 500MB:innodb_data_file_path=ibdata1:12M:autoextend:max:500M

When the autoextend attribute is specified, the data file automatically increases in size by 64MB increments as space is required. The innodb_autoextend_increment variable controls the increment size。--可以設置增長步伐值。

4.Doublewrite Buffer 相關配置

As of MySQL 8.0.20, the doublewrite buffer storage area resides in doublewrite files, which provides flexibility with respect to the storage location of doublewrite pages. In previous releases, the doublewrite buffer storage area resided in the system tablespace. The innodb_doublewrite_dir variable defines the directory where InnoDB creates doublewrite files at startup. If no directory is specified, doublewrite files are created in the innodb_data_home_dir directory, which defaults to the data directory if unspecified.

在8.0.20,doublewrite buffer沒有獨立的文件,是放在了系統表中間文件中了;8.0.20之後,就獨立出來了。

怎麼識別出文件呢?看就需要知道它的命名規則了

Doublewrite file names have the following format: #ib_page_size_file_number.dblwr (or .bdblwr with the DETECT_ONLY setting). For example, the following doublewrite files are created for a MySQL instance with an InnoDB pages size of 16KB and a single buffer pool:

#ib_16384_0.dblwr
#ib_16384_1.dblwr

5.Redo Log相關配置

From MySQL 8.0.30, the amount of disk space occupied by redo log files is controlled by the innodb_redo_log_capacity variable, which can be set at startup or runtime; for example, to set the variable to 8GB in an option file, add the following entry:

[mysqld]
innodb_redo_log_capacity = 8589934592

The innodb_redo_log_capacity variable supersedes【取代;替代】 the innodb_log_file_size and innodb_log_files_in_group variables, which are deprecated. When the innodb_redo_log_capacity setting is defined, the innodb_log_file_size and innodb_log_files_in_group settings are ignored; otherwise, these settings are used to compute the innodb_redo_log_capacity setting (innodb_log_files_in_group * innodb_log_file_size = innodb_redo_log_capacity). If none of those variables are set, innodb_redo_log_capacity is set to the default value, which is 104857600 bytes (100MB). The maximum setting is 128GB.

From MySQL 8.0.30, InnoDB attempts to maintain 32 redo log files, with each file equal to 1/32 * innodb_redo_log_capacity.

Before MySQL 8.0.30, InnoDB creates two 5MB redo log files named ib_logfile0 and ib_logfile1 in the data directory by default. You can define a different number of redo log files and different redo log file size when initializing the MySQL Server instance by configuring the innodb_log_files_in_group and innodb_log_file_size variables.--老版本relog文件的個數和大小設置

• innodb_log_files_in_group defines the number of log files in the log group. The default and recommended value is 2.

• innodb_log_file_size defines the size in bytes of each log file in the log group. The combined log file size (innodb_log_file_size * innodb_log_files_in_group) cannot exceed the maximum value, which is slightly less than 512GB. A pair of 255 GB log files, for example, approaches the limit but does not exceed it. The default log file size is 48MB. Generally, the combined size of the log files should be large enough that the server can smooth out peaks and troughs in workload activity, which often means that there is enough redo log space to handle more than an hour of write activity. A larger log file size means less checkpoint flush activity in the buffer pool, which reduces disk I/O.

6.Undo表空間的相關設置

Undo logs, by default, reside in two undo tablespaces created when the MySQL instance is initialized.【預設2個】

The innodb_undo_directory variable defines the path where InnoDB creates default undo tablespaces. If that variable is undefined, default undo tablespaces are created in the data directory. The innodb_undo_directory variable is not dynamic. Configuring it requires restarting the server.【所在位置】

The I/O patterns for undo logs make undo tablespaces good candidates for SSD storage.【建議放置在SSD中】

7.Global Temporary Tablespace 設置

The global temporary tablespace stores rollback segments for changes made to user-created temporary tables.--用途

A single auto-extending global temporary tablespace data file named ibtmp1 in the innodb_data_home_dir directory by default. The initial file size is slightly larger than 12MB.--命名和預設大小

8.Session Temporary Tablespace設置

In MySQL 8.0.15 and earlier, session temporary tablespaces store user-created temporary tables and internal temporary tables created by the optimizer when InnoDB is configured as the on-disk storage engine for internal temporary tables (internal_tmp_disk_storage_engine=InnoDB). From MySQL 8.0.16, InnoDB is always used as the on-disk storage engine for internal temporary tables.--隨著版本的變化,也獨立了出來

9.Page Size 設置

The innodb_page_size option specifies the page size for all InnoDB tablespaces in a MySQL instance. This value is set when the instance is created and remains constant afterward. Valid values are 64KB, 32KB, 16KB (the default), 8KB, and 4KB. Alternatively, you can specify page size in bytes (65536, 32768, 16384, 8192, 4096).---關鍵變數參數 和 可設置的大小

The default 16KB page size is appropriate for a wide range of workloads, particularly for queries involving table scans and DML operations involving bulk updates. Smaller page sizes might be more efficient for OLTP workloads involving many small writes, where contention can be an issue when a single page contains many rows. Smaller pages can also be more efficient for SSD storage devices, which typically use small block sizes. Keeping the InnoDB page size close to the storage device block size minimizes the amount of unchanged data that is rewritten to disk.---預設為16KB

10.Memory 設置

MySQL allocates memory to various caches and buffers to improve performance of database operations. When allocating memory for InnoDB, always consider memory required by the operating system, memory allocated to other applications, and memory allocated for other MySQL buffers and caches. For example, if you use MyISAM tables, consider the amount of memory allocated for the key buffer (key_buffer_size).

Buffers specific to InnoDB are configured using the following parameters:---主要設置參數

innodb_buffer_pool_size defines size of the buffer pool, which is the memory area that holds cached data for InnoDB tables, indexes, and other auxiliary buffers. The size of the buffer pool is important for system performance, and it is typically recommended that innodb_buffer_pool_size is configured to 50 to 75 percent of system memory. The default buffer pool size is 128MB.----一定要修改,不能使用預設值。

Buffer pool size can be configured at startup or dynamically.

• On systems with a large amount of memory, you can improve concurrency by dividing the buffer pool into multiple buffer pool instances. The number of buffer pool instances is controlled by the by innodb_buffer_pool_instances option. By default, InnoDB creates one buffer pool instance.

The number of buffer pool instances can be configured at startup.

• innodb_log_buffer_size defines the size of the buffer that InnoDB uses to write to the log files on disk. The default size is 16MB. A large log buffer enables large transactions to run without writing the log to disk before the transactions commit. If you have transactions that update, insert, or delete many rows, you might consider increasing the size of the log buffer to save disk I/O.

innodb_log_buffer_size can be configured at startup.

11 記憶體使用(分配)估算的公式

A formula similar to the following that calculates global and per-thread memory allocation for MySQL can be used to estimate MySQL memory usage. You may need to modify the formula to account for buffers and caches in your MySQL version and configuration.

innodb_buffer_pool_size
+ key_buffer_size
+ max_connections*(sort_buffer_size+read_buffer_size+binlog_cache_size)
+ max_connections*2MB

Each thread uses a stack (often 2MB, but only 256KB in MySQL binaries provided by Oracle Corporation.) and in the worst case also uses sort_buffer_size + read_buffer_size additional memory.

 

---------《15.8.1 InnoDB Startup Configuration》

https://dev.mysql.com/doc/refman/8.0/en/innodb-init-startup-configuration.html

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • Arduino IDE 環境配置 目錄Arduino IDE 環境配置1. 安裝方式2. 操作方法(Arduino中文社區)2.1. 安裝Arduino IDE2.2. 下載固件2.3. 修改Arduino IDE語言2.4. 添加開發板管理網址2.5. 運行離線包2.6. 檢查安裝是否成功 1. ...
  • 前提 centos7系統 新建系統時選擇的預設分區 vgs等查看捲組命令無回顯 根目錄磁碟空間不足 大致流程及註意事項 處理方法:刪除再重建 不會導致其中的數據丟失 防止出現意外,請備份或者快照 1.率先在VMware中對虛擬機進行磁碟容量擴容 此處進行20g --> 40g的擴容 2.再在虛擬機中 ...
  • 問題描述 在使用VMWare17.5.0版本安裝ubuntu22.0.4.4的時候遇到問題。安裝完成ubuntu之後,我在虛擬機中點擊滑鼠左鍵沒有問題,單獨按下鍵盤也沒有問題,但是如果按下鍵盤的同時在按下滑鼠左鍵就會卡住。而且100%穩定復現。 具體的卡死按鍵: ctrl+滑鼠左鍵 alt+滑鼠左鍵 ...
  • Ubuntu Server 20.04詳細安裝教程 1. Ubuntu Server20.04啟動盤製作 1.1 下載鏡像 去Ubuntu官網找到20.04的鏡像文件(20.04下載地址),按照自己的需求下載 iso文件 1.2 製作啟動盤 用Rufus製作啟動盤,到官網下載文件(rufus官網) ...
  • 蘇州農商銀行基於GaussDB資料庫,對核心業務系統“超級網銀”進行了全面改造升級,極大提升了系統的穩定性和安全性。 ...
  • 在GreatSQL中,Binlog可以說是 GreatSQL 中比較重要的日誌了,在日常開發及運維過程中經常會遇到。Binlog即Binary Log,二進位日誌文件,也叫作變更日誌(Update Log)。 詳細Binglog日誌介紹 Binglog主要應用於數據恢復和數據複製,但是在Binlog ...
  • 本文分享自華為雲社區《GaussDB(DWS)業務高可靠原理》,作者: yd_291396996。 1. 前言 適用版本:【8.1.0及以上】 GaussDB(DWS)所有內部組件CN、DN、GTM、CM等採用多活或主備設計,通過集群管理進行故障檢測和切換,保證了單點故障場景下業務的可靠性。此外還採 ...
  • windows 安裝sqlserver服務 SQL Server 下載 | Microsoft 或者MSDN, 我告訴你 - 做一個安靜的工具站 (itellyou.cn) 安裝 關閉windows防火牆並重新運行 一路下一步直到 這樣設置可以讓安裝該服務的用戶直接 安裝管理工具 docker 20 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...