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.

For additional MySQL management capabilities, consider using tools like Basedash. It allows you to generate an admin panel for database management, share access with controlled permissions, write and share SQL queries, and create charts and dashboards from your data. Learn more at Basedash.

Invite only

We're building the next generation of data visualization.