Настройка MySQL / MariaDB

Alex

Administrator
Команда форума
LV
0
 
Будем настраивать базу

Отредактируйте /etc/mysql/my.cnf:

Код:
[mysqld]
sql-mode="NO_ENGINE_SUBSTITUTION"
tmpdir      = /dev/shm
skip-external-locking
skip_name_resolve
skip-host-cache
skip-log-bin
skip-networking
skip-innodb_doublewrite
bind-address=localhost
max_connections = 60
symbolic-links=0
sync_binlog = 0
wait_timeout = 60
interactive_timeout = 5
performance_schema = ON
low-priority-updates = 1

table_open_cache = 32000
tmp_table_size = 200M
max_heap_table_size = 200M
max_allowed_packet = 64M
thread_cache_size = 60

innodb_file_format=Barracuda
innodb_flush_log_at_trx_commit = 0
innodb_flush_method = O_DIRECT_NO_FSYNC
innodb_buffer_pool_instances = 1
innodb_buffer_pool_size = 1536M
innodb_log_file_size = 256M
innodb_file_per_table    = 1
innodb_log_buffer_size = 256M
innodb_log_file_size = 192M
innodb_log_files_in_group=2

innodb_stats_on_metadata = 0
innodb_open_files =    65536
innodb_doublewrite = 0
innodb_support_xa = 0
innodb_read_io_threads = 8
innodb_write_io_threads = 8
#innodb_io_capacity=6000
#innodb_io_capacity_max=10000
innodb_thread_concurrency = 4
innodb_checksum_algorithm=crc32
innodb_log_checksum_algorithm=crc32
table_open_cache_instances = 4

[mysqldump]
quick
quote-names
max_allowed_packet    = 64M
default-character-set = utf8mb4

[mysql]
no-auto-rehash
default-character-set = utf8mb4
 

Alex

Administrator
Команда форума
LV
0
 
Нам осталось только изменить (увеличить) приоритет mysql и увеличить лимит на открытие файлов. Раньше это можно было сделать параметром nice и open_file_limits в my.cnf. Теперь в новых версиях это не работает.

Часть настроек теперь находится в /lib/systemd/system/. Отредактируйте файлы mariadb.service и mariadb@.service:

Код:
# Number of files limit. previously [mysqld_safe] open-file-limit
LimitNOFILE=130000

# Nice priority. previously [mysqld_safe] nice
Nice=-10
 

Alex

Administrator
Команда форума
LV
0
 
Сохраните и перезапустите systemd командой


Код:
systemctl daemon-reload
 

Alex

Administrator
Команда форума
LV
0
 
В идеале, если вы все сделали правильно, то mysqltuner должен выдавать вот такую информацию:

— Performance Metrics — [--] Up for: 1d 8h 1m 26s (3M q [31.352 qps], 20K conn, TX: 36G, RX: 660M)
[--] Reads / Writes: 98% / 2%
[--] Binary logging is disabled
[--] Physical Memory: 2.9G
[--] Max MySQL memory: 2.4G
[--] Other process memory: 132.9M
[--] Total buffers: 2.2G global + 3.6M per thread (50 max threads)
[--] P_S Max memory usage: 80M
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 2.3G (79.28% of installed RAM)
[OK] Maximum possible memory usage: 2.4G (84.25% of installed RAM)
[OK] Overall possible memory usage with other process is compatible with memory available
[OK] Slow queries: 0% (0/3M)
[OK] Highest usage of available connections: 18% (9/50)
[OK] Aborted connections: 0.02% (5/20914)
[--] Skipped name resolution test due to skip_networking=ON in system variables.
[OK] Query cache efficiency: 45.7% (2M cached / 6M selects)
[OK] Query cache prunes per day: 49
[OK] Sorts requiring temporary tables: 0% (221 temp sorts / 39K sorts)
[OK] No joins without indexes
[OK] Temporary tables created on disk: 1% (1K on disk / 98K total)
[OK] Thread cache hit rate: 99% (9 created / 20K connections)
[OK] Table cache hit rate:94% (48K open / 59K opened)
[OK] Open file limit used: 0% (71/130K)
[OK] Table locks acquired immediately: 100% (662K immediate / 662K locks)


— InnoDB Metrics — [--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 4
[OK] InnoDB File per table is activated
[OK] InnoDB buffer pool / data size: 1.5G/987.1M
[OK] InnoDB log file size / InnoDB Buffer pool size: 192.0M * 2/1.5G should be equal 25%
[OK] InnoDB buffer pool instances: 1
[--] InnoDB Buffer Pool Chunk Size not used or defined in your version
[OK] InnoDB Read buffer efficiency: 99.99% (151459597 hits/ 151477187 total)
[OK] InnoDB Write log efficiency: 96.88% (540590 hits/ 557984 total)
[OK] InnoDB log waits: 0.00% (0 waits / 17394 writes)


— AriaDB Metrics — [--] AriaDB is enabled.
[OK] Aria pagecache size / total Aria indexes: 128.0M/1B
[OK] Aria pagecache hit rate: 99.5% (8M cached / 46K reads)
 
Сверху