Sys-Admin Forum

Оптимизация DB mysql + phpmyadmin

Есть база сайта в mysql объёмом в 50МБ. Задался целью оптимизировать и ускорить производительность mysql. Так как озу - 8гб, сейчас занято 1,3-1,4 ГБ + в свап залезло 500 МБ. Подскажите пожалуйста, что и как мне подшаманить с mysql, для повышения эффективности? Может еще какие то идеи. И да, опыта работы с myaql -мало. :sunglasses:
Конфиг my.cnf

Сводка

[client]
port=3306
socket=/var/run/mysqld/mysqld.sock

[mysqld_safe]
socket=/var/run/mysqld/mysqld.sock

[mysqld]
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
log_error=/var/log/mysql/error.log

symbolic-links=0

skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 32M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
#innodb_use_native_aio = 0
innodb_file_per_table

max_connections=200
max_user_connections=50
wait_timeout=10
interactive_timeout=50
long_query_time=5

!includedir /etc/mysql/conf.d/

Скрин phpmyadmin - Состояние.
Screenshot_20200115_140030
Screenshot_20200115_142157

Привет, даю подсказку :slight_smile:

mysqltuner выдал такой отчет. Как есть. Пароль рута на sql = пустой, это понятно. Нужно его установить. В конце параметры:
query_cache_size (=0)
query_cache_type (=0)
query_cache_limit (> 1M, or use smaller result sets)
tmp_table_size (> 16M)
max_heap_table_size (> 16M)
table_open_cache (> 256)
innodb_log_file_size should be (=16M) if possible, so InnoDB total log files size equals to 25% of buffer pool size.
То есть скрипт предлагает мне установить эти параметры?

Под кат

[–] Skipped version check for MySQLTuner script
[OK] Logged in using credentials from Debian maintenance account.
[OK] Currently running supported MySQL
[OK] Operating on 64-bit architecture

-------- Log file Recommendations ------------------------------------------------------------------
[OK] Log file /var/log/mysql/error.log exists
[–] Log file: /var/log/mysql/error.log(9K)
[OK] Log file /var/log/mysql/error.log is readable.
[OK] Log file /var/log/mysql/error.log is not empty
[OK] Log file /var/log/mysql/error.log is smaller than 32 Mb
[OK] /var/log/mysql/error.log doesn’t contain any warning.
[OK] /var/log/mysql/error.log doesn’t contain any error.
[–] 0 start(s) detected in /var/log/mysql/error.log
[–] 0 shutdown(s) detected in /var/log/mysql/error.log

-------- Storage Engine Statistics -----------------------------------------------------------------
[–] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MEMORY +MRG_MYISAM +MyISAM +PERFORMANCE_SCHEMA
[–] Data in MyISAM tables: 26.6M (Tables: 57)
[–] Data in InnoDB tables: 24.4M (Tables: 37)
[OK] Total fragmented tables: 0

-------- Analysis Performance Metrics --------------------------------------------------------------
[–] innodb_stats_on_metadata: OFF
[OK] No stat updates during querying INFORMATION_SCHEMA.

-------- Security Recommendations ------------------------------------------------------------------
[OK] There are no anonymous accounts for any database users
[!!] User ‘[email protected]’ has no password set.
[!!] User ‘admin_@%’ does not specify hostname restrictions.
[!!] User 'admin-
@%’ does not specify hostname restrictions.
[!!] There is no basic password file list!

-------- CVE Security Recommendations --------------------------------------------------------------
[–] Skipped due to --cvefile option undefined

-------- Performance Metrics -----------------------------------------------------------------------
[–] Up for: 4d 17h 58m 51s (9M q [23.549 qps], 354K conn, TX: 8G, RX: 1G)
[–] Reads / Writes: 95% / 5%
[–] Binary logging is disabled
[–] Physical Memory : 7.8G
[–] Max MySQL memory : 7.9G
[–] Other process memory: 0B
[–] Total buffers: 432.0M global + 38.5M per thread (200 max threads)
[–] P_S Max memory usage: 72B
[–] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 817.0M (10.28% of installed RAM)
[!!] Maximum possible memory usage: 7.9G (102.31% of installed RAM)
[!!] Overall possible memory usage with other process exceeded memory
[OK] Slow queries: 0% (0/9M)
[OK] Highest usage of available connections: 5% (10/200)
[OK] Aborted connections: 0.11% (402/354973)
[!!] name resolution is active : a reverse name resolution is made for each new connection and can reduce performance
[!!] Query cache may be disabled by default due to mutex contention.
[!!] Query cache efficiency: 0.0% (0 cached / 7M selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (3K temp sorts / 671K sorts)
[OK] No joins without indexes
[!!] Temporary tables created on disk: 33% (670K on disk / 1M total)
[OK] Thread cache hit rate: 99% (12 created / 354K connections)
[!!] Table cache hit rate: 2% (256 open / 10K opened)
[OK] table_definition_cache(528) is upper than number of tables(373)
[OK] Open file limit used: 4% (224/5K)
[OK] Table locks acquired immediately: 99% (9M immediate / 9M locks)

-------- Performance schema ------------------------------------------------------------------------
[–] Memory used by P_S: 72B
[–] Sys schema is installed.

-------- ThreadPool Metrics ------------------------------------------------------------------------
[–] ThreadPool stat is disabled.

-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 20.3% (54M used / 268M cache)
[OK] Key buffer size / total MyISAM indexes: 256.0M/7.8M
[OK] Read Key buffer hit rate: 100.0% (4B cached / 3K reads)
[!!] Write Key buffer hit rate: 58.3% (464K cached / 270K writes)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[–] InnoDB is enabled.
[–] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[OK] InnoDB buffer pool / data size: 128.0M/24.4M
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (75 %): 48.0M * 2/128.0M should be equal to 25%
[OK] InnoDB buffer pool instances: 1
[–] Number of InnoDB Buffer Pool Chunk : 1 for 1 Buffer Pool Instance(s)
[OK] Innodb_buffer_pool_size aligned with Innodb_buffer_pool_chunk_size & Innodb_buffer_pool_instances
[OK] InnoDB Read buffer efficiency: 100.00% (449695597 hits/ 449695924 total)
[OK] InnoDB Write log efficiency: 99.10% (79351 hits/ 80072 total)
[OK] InnoDB log waits: 0.00% (0 waits / 721 writes)

-------- AriaDB Metrics ----------------------------------------------------------------------------
[–] AriaDB is disabled.

-------- TokuDB Metrics ----------------------------------------------------------------------------
[–] TokuDB is disabled.

-------- XtraDB Metrics ----------------------------------------------------------------------------
[–] XtraDB is disabled.

-------- Galera Metrics ----------------------------------------------------------------------------
[–] Galera is disabled.

-------- Replication Metrics -----------------------------------------------------------------------
[–] Galera Synchronous replication: NO
[–] No replication slave(s) for this server.
[–] Binlog format: ROW
[–] XA support enabled: ON
[–] Semi synchronous replication Master: Not Activated
[–] Semi synchronous replication Slave: Not Activated
[–] This is a standalone server

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
Set up a Secure Password for [email protected] user: SET PASSWORD FOR ‘root’@‘SpecificDNSorIp’ = PASSWORD(‘secure_password’);
Restrict Host for ‘admin_’@% to admin_[email protected]
UPDATE mysql.user SET host =‘SpecificDNSorIp’ WHERE user='admin_
’ AND host =’%’; FLUSH PRIVILEGES;
Restrict Host for 'admin-
’@% to admin-@SpecificDNSorIp
UPDATE mysql.user SET host =‘SpecificDNSorIp’ WHERE user='admin-
’ AND host =’%’; FLUSH PRIVILEGES;
Reduce your overall MySQL memory footprint for system stability
Dedicate this server to your database for highest performance.
Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1
When making adjustments, make tmp_table_size/max_heap_table_size equal
Reduce your SELECT DISTINCT queries which have no LIMIT clause
Increase table_open_cache gradually to avoid file descriptor limits
Read this before increasing table_open_cache over 64: https://bit.ly/2Fulv7r
Read this before increasing for MariaDB https://mariadb.com/kb/en/library/optimizing-table_open_cache/
This is MyISAM only table_cache scalability problem, InnoDB not affected.
See more details here: https://bugs.mysql.com/bug.php?id=49177
This bug already fixed in MySQL 5.7.9 and newer MySQL versions.
Beware that open_files_limit (5000) variable
should be greater than table_open_cache (256)
Before changing innodb_log_file_size and/or innodb_log_files_in_group read this: https://bit.ly/2TcGgtU
Variables to adjust:
*** MySQL’s maximum memory usage is dangerously high ***
*** Add RAM before increasing MySQL buffer variables ***
query_cache_size (=0)
query_cache_type (=0)
query_cache_limit (> 1M, or use smaller result sets)
tmp_table_size (> 16M)
max_heap_table_size (> 16M)
table_open_cache (> 256)
innodb_log_file_size should be (=16M) if possible, so InnoDB total log files size equals to 25% of buffer pool size.

Поиграйся с различными параметрами, тебе это реально поможет сэкономит память и в принципе ресурсы твоего VPS.

1 Симпатия

После всех манипуляций, проб и ошибок вышел ниже приведенный конфиг. Много времени заняло оптимизация, ожидание работы минимум сервера 2-3 часа после рестарта. Можно и меньше, но… .
Спасибо большое за помощь. :sunglasses:

Сводка

skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 32M
#table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
#query_cache_size= 16M

#innodb_use_native_aio = 0
innodb_file_per_table
#max_connections=200
#max_user_connections=50
wait_timeout=10
interactive_timeout=50
long_query_time=5

#add after mysqltuner test
query_cache_size=0
query_cache_type=0
query_cache_limit=8M
tmp_table_size=256M
max_heap_table_size=256M
table_open_cache=1024
innodb_log_file_size=16M
max_connections=64
max_user_connections=16

Спасибо за шаринг конфигурации MySQL.

Подскажи пожалуйста конфигурацию своего VPS (память, проц)

Сервер:
Процессор: Xeon E3-1230V2, Частота: 4 × 3.3 ГГц, ОЗУ: 8 ГБ, Диски: 2 × 960ГБ SSD
Screenshot_20200121_083513