Skip to content

MySQL’s configuration file, often referred to as my.cnf or my.ini, is a critical file for managing server behavior. It allows you to customize settings to optimize performance, security, and other aspects of MySQL operations.

What is the MySQL Configuration File?

MySQL reads several configuration files upon startup, and the specific file locations may vary depending on the operating system. The main configuration file is typically named my.cnf on Linux and macOS, or my.ini on Windows.

Where is the MySQL Config File?

  • Linux/Unix/macOS: /etc/my.cnf, /etc/mysql/my.cnf, ~/.my.cnf
  • Windows: C:\\ProgramData\\MySQL\\MySQL Server x.x\\my.ini

Key Sections of the Config File

  • [mysqld]: Server-specific parameters.
  • [mysqld_safe]: Parameters for the mysqld_safe script.
  • [client]: Options for all client programs.
  • [mysql]: Specific options for the mysql client.

Configuring Server Options

Basic Server Settings

[mysqld]
port = 3306
socket = /tmp/mysql.sock
key_buffer_size = 16M
max_allowed_packet = 8M
  • port: Specifies the port MySQL server listens on.
  • socket: Location of the socket file used for local connections.
  • key_buffer_size: Size of the buffer used for index blocks.
  • max_allowed_packet: Maximum size of packets sent between the server and clients.

Performance Tuning

query_cache_size = 32M
table_open_cache = 2000
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
  • query_cache_size: Memory allocated for caching query results.
  • table_open_cache: Number of open tables for all threads.
  • innodb_buffer_pool_size: Size of the buffer pool for InnoDB tables.
  • innodb_log_file_size: Size of each log file in a log group for InnoDB.

Security Settings

[mysqld]
local_infile = 0
  • local_infile: Disables the use of LOAD DATA LOCAL INFILE to prevent data loading from arbitrary files.

Configuring Client Programs

Basic Client Configuration

[client]
port = 3306
socket = /tmp/mysql.sock
  • These settings ensure client programs can connect to the server using the same port and socket.

Advanced Features

Logging and Debugging

[mysqld]
general_log = 1
general_log_file = /var/log/mysql/mysql.log
log_error = /var/log/mysql/error.log
  • general_log: Enables general query logging.
  • log_error: Specifies the error log file location.

Including Other Config Files

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
  • MySQL can include settings from other files using !includedir.

Basedash is built as an AI-native BI platform, so teams can go from ad hoc SQL to trusted answers and dashboards quickly, without the overhead of traditional BI setup.

Written by

Robert Cooper avatar

Robert Cooper

Senior Engineer at Basedash

Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.

View full author profile →

Looking for an AI-native BI tool?

Basedash lets you build charts, dashboards, and reports in seconds using all your data.