Convert MySQL my.cnf Configuration to JSON
Convert MySQL's my.cnf (or my.ini on Windows) configuration file to JSON. Covers client, mysqld, and mysqldump sections with their specific options.
Common Files
Detailed Explanation
MySQL my.cnf to JSON
MySQL's my.cnf (or my.ini on Windows) is the primary configuration file for the MySQL database server and client programs. It uses INI format with sections for different MySQL programs.
Example my.cnf
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
default-character-set = utf8mb4
[mysqld]
port = 3306
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
bind-address = 127.0.0.1
max_connections = 200
max_allowed_packet = 64M
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 1
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2
[mysqldump]
quick
max_allowed_packet = 64M
Generated JSON
{
"client": {
"port": 3306,
"socket": "/var/run/mysqld/mysqld.sock",
"default-character-set": "utf8mb4"
},
"mysqld": {
"port": 3306,
"socket": "/var/run/mysqld/mysqld.sock",
"datadir": "/var/lib/mysql",
"bind-address": "127.0.0.1",
"max_connections": 200,
"max_allowed_packet": "64M",
"innodb_buffer_pool_size": "1G",
"innodb_log_file_size": "256M",
"innodb_flush_log_at_trx_commit": 1,
"slow_query_log": 1,
"slow_query_log_file": "/var/log/mysql/slow.log",
"long_query_time": 2
},
"mysqldump": {
"quick": true,
"max_allowed_packet": "64M"
}
}
MySQL-Specific Considerations
- Valueless keys:
quickunder[mysqldump]is a boolean flag with no=sign. The converter treats it astruewith the "Valueless keys as true" option - Size suffixes: Values like
64M,1G,256Mcontain unit suffixes and remain as strings - Hyphenated keys: MySQL accepts both
bind-addressandbind_address; the converter preserves the original form - Multiple programs: Each section (
[client],[mysqld],[mysqldump]) configures a different MySQL program - Shared options: Some keys like
portandsocketappear in multiple sections with the same or different values
Use Case
Building a MySQL configuration management system that reads my.cnf files as JSON, allows infrastructure engineers to modify settings through a web interface, and generates optimized my.cnf files for different server roles (primary, replica, analytics).