# MySQL/MariaDB Optimization for GengSewa
# For handling 3000+ bookings per month (100+ requests per day)
# Copy this to your MySQL/MariaDB configuration directory
# Windows: C:\laragon\bin\mysql\mysql-X.X.X\my.ini
# Linux: /etc/mysql/my.cnf or /etc/my.cnf

[mysqld]
# === CONNECTION SETTINGS ===
max_connections = 500
max_user_connections = 450
wait_timeout = 600
interactive_timeout = 600
connect_timeout = 10

# === BUFFER POOL (Most Important for InnoDB) ===
# Set to 70-80% of available RAM if dedicated DB server
# For 4GB RAM, use 2-3GB
# For 8GB RAM, use 5-6GB
innodb_buffer_pool_size = 2G
innodb_buffer_pool_instances = 4

# === QUERY CACHE (if MySQL <5.7) ===
query_cache_type = 1
query_cache_size = 128M
query_cache_limit = 2M

# === INNODB SETTINGS ===
innodb_log_file_size = 512M
innodb_log_buffer_size = 64M
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
innodb_file_per_table = 1
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
innodb_read_io_threads = 8
innodb_write_io_threads = 8

# === TABLE CACHE ===
table_open_cache = 4000
table_definition_cache = 2000
open_files_limit = 10000

# === TEMP TABLES ===
tmp_table_size = 128M
max_heap_table_size = 128M

# === SORT & JOIN BUFFERS ===
sort_buffer_size = 4M
join_buffer_size = 4M
read_buffer_size = 2M
read_rnd_buffer_size = 4M

# === THREAD SETTINGS ===
thread_cache_size = 100
thread_stack = 256K

# === MyISAM (if used) ===
key_buffer_size = 128M
myisam_sort_buffer_size = 128M

# === BINARY LOGGING (for replication/backup) ===
binlog_cache_size = 32K
max_binlog_size = 512M
expire_logs_days = 7
binlog_format = ROW

# === SLOW QUERY LOG (for optimization) ===
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow-query.log
long_query_time = 2
log_queries_not_using_indexes = 1

# === CHARACTER SET ===
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

# === PERFORMANCE SCHEMA (for monitoring) ===
performance_schema = ON
performance_schema_max_table_instances = 12500

[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4
