Skip to content

Commit

Permalink
optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
aliuosio committed Oct 9, 2024
1 parent d881db0 commit 0b67a7d
Showing 1 changed file with 78 additions and 177 deletions.
255 changes: 78 additions & 177 deletions .docker/mysql/config/my.cnf
Original file line number Diff line number Diff line change
@@ -1,212 +1,113 @@
# MariaDB database server configuration file.
#
# You can copy this file to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations performance_schema = on
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# MariaDB database server configuration optimized for Magento 2.

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
port = 3306
socket = /var/run/mysqld/mysqld.sock
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4
# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
#socket = /var/run/mysqld/mysqld.sock
nice = 0
nice = 0

[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc_messages_dir = /usr/share/mysql
lc_messages = en_US
skip-external-locking
bind-address = 127.0.0.1 # Consider enabling this for security (bind to localhost)
skip-name-resolve # Improves performance by skipping DNS resolution

# Character set and collation optimized for Magento 2
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

# user added
performance_schema = on

#user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc_messages_dir = /usr/share/mysql
lc_messages = en_US
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
#
# * Fine Tuning
#
max_connections = 400
connect_timeout = 5
wait_timeout = 600
max_allowed_packet = 512M
thread_cache_size = 256
sort_buffer_size = 8M
bulk_insert_buffer_size = 32M
tmp_table_size = 256M
max_heap_table_size = 256M
table_definition_cache = -1
#
# * MyISAM
#
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched. On error, make copy and try a repair.
myisam_recover_options = BACKUP
key_buffer_size = 128M
#open-files-limit = 2000
table_open_cache = 2048
myisam_sort_buffer_size = 512M
concurrent_insert = 2
read_buffer_size = 2M
read_rnd_buffer_size = 1M
# Increase maximum allowed connections
max_connections = 500

# Memory limits for performance
max_allowed_packet = 512M
thread_cache_size = 512
sort_buffer_size = 4M
read_buffer_size = 4M
read_rnd_buffer_size = 16M
join_buffer_size = 4M
tmp_table_size = 512M
max_heap_table_size = 512M
table_open_cache = 4096
table_definition_cache = 4096

# Timeout settings
connect_timeout = 10
wait_timeout = 600
interactive_timeout = 600

#
# * Query Cache Configuration
#
# Cache only tiny result sets, so we can fit more in the query cache.
query_cache_limit = 0
query_cache_size = 0
# for more write intensive setups, set to DEMAND or OFF
query_cache_type = 0
# Magento 2 does not benefit from query cache; leave it disabled
query_cache_limit = 0
query_cache_size = 0
query_cache_type = 0

#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
general_log = 0
general_log = 0 # Disable general log for better performance
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mariadb-slow.log
long_query_time = 1 # Capture queries longer than 1 second

#
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
#
# we do want to know about network errors and such
#log_warnings = 2
#
# Enable the slow query log to see queries with especially long duration
#slow_query_log[={0|1}]
slow_query_log=0
slow_query_log_file = /var/log/mysql/mariadb-slow.log
long_query_time = 10
#log_slow_rate_limit = 1000
#log_slow_verbosity = query_plan

#log-queries-not-using-indexes
#log_slow_admin_statements
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id = 1
#report_host = master1
#auto_increment_increment = 2
#auto_increment_offset = 1
#log_bin = /var/log/mysql/mariadb-bin
#log_bin_index = /var/log/mysql/mariadb-bin.index
# not fab for performance, but safer
sync_binlog = 0
expire_logs_days = 10
max_binlog_size = 100M
# slaves
slave_net_timeout = 4
#relay_log = /var/log/mysql/relay-bin
#relay_log_index = /var/log/mysql/relay-bin.index
#relay_log_info_file = /var/log/mysql/relay-bin.info
#log_slave_updates
#read_only
#
# If applications support it, this stricter sql_mode prevents some
# mistakes like inserting invalid dates etc.
#sql_mode = NO_ENGINE_SUBSTITUTION,TRADITIONAL
sql_mode = STRICT_TRANS_TABLES
# Binlog settings for transactional safety (optional, can disable for single-server setup)
log_bin = /var/log/mysql/mariadb-bin
sync_binlog = 1 # Ensure transactional safety, especially for eCommerce
expire_logs_days = 14
max_binlog_size = 100M

#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 400
innodb_io_capacity = 400
innodb_flush_method = O_DIRECT
innodb_log_buffer_size = 16M
innodb_log_file_size = 5M
innodb_thread_concurrency = 12
innodb_lock_wait_timeout = 7200
innodb_flush_method = O_DIRECT
innodb_flush_log_at_trx_commit = 2
innodb_log_files_in_group = 2
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_file_per_table = 1
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_buffer_pool_instances = 2
innodb_buffer_pool_size = 4G
innodb_stats_on_metadata = 0
# * InnoDB Settings
#
# InnoDB is the default and most important storage engine for Magento 2
innodb_buffer_pool_size = 8G # Set to 50-70% of total RAM for the server (adjust based on available memory)
innodb_buffer_pool_instances = 8 # Split buffer pool into multiple instances for better concurrency
innodb_log_file_size = 512M # Size of redo logs; 512MB is optimal for most eCommerce setups
innodb_log_buffer_size = 64M # Redo log buffer
innodb_flush_method = O_DIRECT # Reduce OS caching and improve I/O performance
innodb_flush_log_at_trx_commit = 1 # Ensure ACID compliance; set to 1 for transactional safety (critical for eCommerce)
innodb_file_per_table = 1 # Each InnoDB table in its own file for better performance and easier maintenance
innodb_io_capacity = 2000 # Increase if running on SSD to improve write performance
innodb_read_io_threads = 16 # Increase for better I/O concurrency (especially on SSDs)
innodb_write_io_threads = 16
innodb_lock_wait_timeout = 300 # Allow longer lock waits, especially important for large transactions in Magento
innodb_stats_on_metadata = 0 # Disable gathering stats on metadata to reduce overhead

#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem
# Ensure faster InnoDB recovery in case of crash
innodb_autoinc_lock_mode = 2

#
# * Galera-related settings
#
[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0
# Optional settings to consider based on server capacity and workload
# innodb_thread_concurrency = 16 # Uncomment and adjust based on CPU cores

[mysqldump]
quick
quote-names
max_allowed_packet = 16M
max_allowed_packet = 16M

[isamchk]
key_buffer = 16M
key_buffer = 16M

#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
# Additional Settings
#
# File locations
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/

0 comments on commit 0b67a7d

Please sign in to comment.