MySQL Tutorial

MySQL Installation and Configuration

MySQL Database Operations

Database Design

MySQL Data Types

MySQL Storage Engines

MySQL Basic Operations of Tables

MySQL Constraints

MySQL Operators

MySQL Function

MySQL Manipulate Table Data

MySQL View

MySQL Indexes

MySQL Stored Procedure

MySQL Trigger

MySQL Transactions

MySQL Character Set

MySQL User Management

MySQL Database Backup and Recovery

MySQL Log

MySQL Performance Optimization

MySQL my.ini Configuration File

my.ini is the configuration file used in the MySQL database. The MySQL server will read this configuration file when it starts up. We can modify this file to achieve the purpose of updating the configuration. This section uses the my.ini configuration file under Windows system as a template to explain the parameters in the MySQL configuration file.
For the convenience of readers, we omit the comments in the my.ini file. The specific meanings of the parameters in my.ini are introduced separately below. The contents of the file are as follows:
[client]
port=3306
[mysql]
default-character-set=gbk
The above shows the parameters of the client. [client] and [mysql] are both clients. The parameters are described as follows:
  • port: indicates the port number used by the MySQL client to connect to the server. The default port number is 3306. If you need to change the port number, you can modify it directly here.
  • default-character-set: Indicates the default character set of the MySQL client.
[mysqld]

port=3306
basedir=C:/Program Files/MySQL/MySQL Server 5.7/
datadir=C:/ProgramData/MySQL/MySQL Server 5.7/Data

character-set-server=gb2312
default-storage-engine=INNODB
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

max_connections=100
query_cache_size=0
table_cache=256
tmp_table_size=35M
thread_cache_size=8
myisam_max_sort_file_size=100G
myisam_sort_buffer_size=69M
key_buffer_size=55M
read_buffer_size=64K
read_rnd_buffer_size=256K
sort_buffer_size=256K
The above are the parameters of the server. The parameter descriptions are shown in the following table:

parameter name illustrate
port Indicates the port number of the MySQL server
basedir Indicates the installation path of MySQL
datadir Indicates the storage location of MySQL data files, and also the storage location of data tables
default-character-set Indicates the server-side default character set
default-storage-engine When creating a data table, the default storage engine used
sql-mode Indicates the parameter of the SQL mode, through which the strictness of the SQL statement can be set
max_connections Indicates the maximum number of connections allowed to access the MySQL server at the same time. One of the connections is reserved, reserved for the exclusive use of the administrator
query_cache_size Indicates the size of the cache at the time of query. The cache can store information previously queried through the SELECT statement. When querying again, the information can be directly retrieved from the cache, which can improve query efficiency.
table_open_cache Indicates the total number of open tables for all processes
tmp_table_size Indicates the maximum size allowed for each temporary table in memory
thread_cache_size Indicates the maximum number of threads to cache
myisam_max_sort_file_size Indicates the maximum size of temporary files allowed by MySQL when rebuilding indexes
myisam_sort_buffer_size Indicates the cache size when rebuilding the index
key_buffer_size Indicates the cache size of the keyword
read_buffer_size Indicates the size of the cache for full table scans of MyISAM tables
read_rnd_buffer_size Indicates that the sorted data is stored in the cache
sort_buffer_size Indicates the size of the cache used for sorting
 
innodb_additional_mem_pool_size=3M
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=2M
innodb_buffer_pool_size=107M
innodb_log_file_size=54M
innodb_thread_concurrency=18
The above are the parameters used by the InnoDB storage engine. The parameter descriptions are as follows:
  • innodb_additional_mem_pool_size: Indicates an additional memory pool used to store the contents of InnoDB tables.
  • innodb_flush_log_at_trx_commit: is the timing to set the commit log. If set to 1, InnoDB will write the transaction log to disk after each commit.
  • innodb_log_buffer_size: Indicates the size of the buffer used to store log data.
  • innodb_buffer_pool_size: Indicates the size of the cache. InnoDB uses a buffer pool class to store indexes and raw data.
  • innodb_log_file_size: Indicates the size of the log file.
  • innodb_thread_concurrency: Indicates the maximum number of threads allowed in the InnoDB storage engine.

Note: After each modification of the parameters in the my.ini file, the MySQL service must be restarted to take effect.
  1. Edit my.ini for MySQL Configuration on Windows:

    • Description: Edit the my.ini file using a text editor to adjust MySQL server settings on Windows.
    • Code: Open the file using a text editor such as Notepad:
      notepad "C:\Program Files\MySQL\MySQL Server X.Y\my.ini"
      
      Adjust the path based on your MySQL installation.
  2. Changing Buffer Settings in my.ini:

    • Description: Adjust buffer settings like innodb_buffer_pool_size in the my.ini file to optimize MySQL's use of memory.
    • Code: Edit my.ini and set values, e.g.:
      innodb_buffer_pool_size = 256M
      
  3. Reload my.ini Without Restarting MySQL on Windows:

    • Description: Reload the MySQL configuration without restarting the server to apply changes on Windows.
    • Code:
      mysqladmin -u root -p shutdown
      mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server X.Y\my.ini"
      
      Adjust the path based on your MySQL installation.