Benutzer-Werkzeuge

Webseiten-Werkzeuge


mysql_tuning

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
mysql_tuning [2022-02-24 12:16:44] – [MySQL Tuning] manfredmysql_tuning [2024-11-13 11:33:51] (aktuell) – [mysqltuner.pl funktioniert nicht mit PXC] manfred
Zeile 1: Zeile 1:
-===== MySQL Tuning =====+====== MySQL Tuning ======
  
 siehe auch: siehe auch:
 +  * [[https://github.com/major/MySQLTuner-perl]]
 +    * ''> git clone https://github.com/major/MySQLTuner-perl.git''
 +    * ''> ls -1 MySQLTuner-perl/mysqltuner.pl''
 +    * ''MySQLTuner-perl/mysqltuner.pl''
   * [[::MySQL - Benchmark]]   * [[::MySQL - Benchmark]]
   * [[::MySQL-Lasttest]]   * [[::MySQL-Lasttest]]
   * [[::MySQL Tuning]]   * [[::MySQL Tuning]]
-  * [[::MySQL Performance Tuning]] 
  
  
-==== Ab MySQL 8.0 ====+===== Ab MySQL 8.0 =====
  
   * [[https://dev.mysql.com/doc/refman/8.0/en/optimizing-innodb-diskio.html|8.5.8 Optimizing InnoDB Disk I/O]]   * [[https://dev.mysql.com/doc/refman/8.0/en/optimizing-innodb-diskio.html|8.5.8 Optimizing InnoDB Disk I/O]]
Zeile 35: Zeile 38:
  
 Es sollten von der MySQL-DB nur max. 84% des RAM belegt werden. Es sollten von der MySQL-DB nur max. 84% des RAM belegt werden.
-  innodb_buffer_pool_size + ( max_allowed_packet * max_connections ) <= 84% RAM+  innodb_buffer_pool_size + ( max_allowed_packet * max_connections ) <= 70-84% RAM
  
 beide Konfigurationen belegen so ziehmlich die gleiche Menge RAM: beide Konfigurationen belegen so ziehmlich die gleiche Menge RAM:
Zeile 56: Zeile 59:
  
  
-==== Bis MySQL 5.7 ====+===== Bis MySQL 5.7 =====
  
   * [[http://dev.mysql.com/doc/refman/5.1/de/innodb-tuning.html]]   * [[http://dev.mysql.com/doc/refman/5.1/de/innodb-tuning.html]]
Zeile 166: Zeile 169:
   query_cache_size= 512M   query_cache_size= 512M
   query_cache_type= 1   query_cache_type= 1
 +
  
  
Zeile 339: Zeile 343:
   [server]   [server]
   sql-mode=""   sql-mode=""
 +
 +
 +==== Performance Schema ====
 +
 +
 +
 +=== getestet mit Ubuntu 14.04.5 LTS / mysqld 5.7.21 ===
 +
 +<file sql events_statements_history.sql>
 +SELECT * FROM performance_schema.setup_consumers;
 +
 +SET GLOBAL show_compatibility_56 = ON;
 +
 +SELECT left(digest_text, 64) AS query
 +, ROUND(SUM(timer_end-timer_start)/1000000000, 1) AS tot_exec_ms
 +, ROUND(SUM(timer_wait)/1000000000, 1) AS tot_wait_ms
 +, ROUND(SUM(lock_time)/1000000000, 1) AS tot_lock_ms
 +, MIN(LEFT(DATE_SUB(NOW(), INTERVAL (isgs.VARIABLE_VALUE - TIMER_START*10e-13) second), 19)) AS first_seen
 +, MAX(LEFT(DATE_SUB(NOW(), INTERVAL (isgs.VARIABLE_VALUE - TIMER_START*10e-13) second), 19)) AS last_seen
 +, COUNT(*) as cnt
 +FROM performance_schema.events_statements_history
 +JOIN information_schema.global_status AS isgs
 +WHERE isgs.variable_name = 'UPTIME'
 +GROUP BY LEFT(digest_text,64)
 +ORDER BY tot_exec_ms DESC
 +LIMIT 10;
 +</file>
 +
 +<file sql events_statements_history_long.sql>
 +SELECT * FROM performance_schema.setup_consumers;
 +
 +UPDATE performance_schema.setup_consumers SET enabled = 1 WHERE name = 'events_statements_history_long';
 +SET GLOBAL show_compatibility_56 = ON;
 +
 +SELECT left(digest_text, 64) AS query
 +, ROUND(SUM(timer_end-timer_start)/1000000000, 1) AS tot_exec_ms
 +, ROUND(SUM(timer_wait)/1000000000, 1) AS tot_wait_ms
 +, ROUND(SUM(lock_time)/1000000000, 1) AS tot_lock_ms
 +, MIN(LEFT(DATE_SUB(NOW(), INTERVAL (isgs.VARIABLE_VALUE - TIMER_START*10e-13) second), 19)) AS first_seen
 +, MAX(LEFT(DATE_SUB(NOW(), INTERVAL (isgs.VARIABLE_VALUE - TIMER_START*10e-13) second), 19)) AS last_seen
 +, COUNT(*) as cnt
 +FROM performance_schema.events_statements_history_long
 +JOIN information_schema.global_status AS isgs
 +WHERE isgs.variable_name = 'UPTIME'
 +GROUP BY LEFT(digest_text,64)
 +ORDER BY tot_exec_ms DESC
 +LIMIT 10;
 +</file>
 +
 +
 +===== mysqltuner.pl =====
 +
 +  * [[http://dev.mysql.com/doc/refman/5.1/de/innodb-tuning.html]]
 +  * ''wget -O mysqltuner.pl http://mysqltuner.pl''
 +    * [[https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl]]
 +
 +  > perl mysqltuner.pl --user root --pass geheim --host 192.168.1.1 --port 3306
 +  
 +  oder
 +  
 +  > touch ~/.my.cnf
 +  > chmod 0600 ~/.my.cnf
 +  > vi ~/.my.cnf
 +  > perl mysqltuner.pl --defaults-file ~/.my.cnf
 +
 +für Zugriffe über das Netz, hier muß der Option ''-____-forcemem'' die RAM-Größe (in MB) des DB-Systems mitgegeben werden, in diesem Fall sind es 4 GB:
 +  > perl mysqltuner.pl --forcemem 4096 --forceswap 4096 --user root --pass geheim --host 192.168.1.1 --port 3306
 +
 +  > perl mysqltuner.pl --defaults-file ~/.my.cnf 2>&1 | tee mysqltuner_-_$(date +'%F_%H-%M-%S').log
 +
 +
 +==== mysqltuner.pl funktioniert nicht mit PXC ====
 +
 +<code c Der Fehler>
 +# wget http://mysqltuner.pl/ -O mysqltuner.pl
 +# perl mysqltuner.pl --forcemem 8000000000 --forceswap 8000000000 --defaults-file /root/.my.cnf --defaults-extra-file /etc/mysql/conf.d_23357/my.cnf --port 23357
 + >>  MySQLTuner 2.5.3
 + * Jean-Marie Renouard <jmrenouard@gmail.com>
 + * Major Hayden <major@mhtx.net>
 + >>  Bug reports, feature requests, and downloads at http://mysqltuner.pl/
 + >>  Run with '--help' for additional options and output filtering
 +
 +[--] Skipped version check for MySQLTuner script
 +mysql: [ERROR] unknown option '--print-defaults'
 +mysql: [ERROR] unknown option '--print-defaults'
 +[--] Assuming 8000000000 MB of physical memory
 +[--] Assuming 8000000000 MB of swap space
 +[!!] Failed to execute: SELECT VERSION()
 +[!!] FAIL Execute SQL / return code: 1792
 +[!!] You probably do not have enough privileges to run MySQLTuner ...
 +</code>
 +
 +<code c Fehler nachstellen>
 +# /usr/bin/mysql --port 23357 --print-defaults
 +mysql: [ERROR] unknown option '--print-defaults'
 +</code>
 +
 +<code c Client-Ursprung ermitteln>
 +# dpkg -S mysql | grep -F bin | grep -E mysql$
 +percona-xtradb-cluster-client-5.7: /usr/bin/mysql
 +</code>
 +
 +<code c Der Grund steht in der Hilfe>
 +# /usr/bin/mysql --help
 +...
 +The following options may be given as the first argument:
 +--print-defaults        Print the program argument list and exit.
 +...
 +</code>
 +
 +<code c Test ist nicht befriedigend>
 +# /usr/bin/mysql --print-defaults --port 23357
 +/usr/bin/mysql would have been started with the following arguments:
 +--port=3306 --socket=/var/run/mysqld/mysqld.sock --host=localhost --user=root --password=***** --port 23357 
 +</code>
  
  
Zeile 363: Zeile 482:
      
   replicate_wild_ignore_table     = DatenbankName.%   replicate_wild_ignore_table     = DatenbankName.%
 +
 +
 +===== MyISAM-Tuning =====
 +
 +[[https://mariadb.com/kb/en/myisam-system-variables/|MyISAM System Variables]]
 +
 +prüfen, ob ''key_buffer_size'' richtig dimensioniert ist:
 +  > echo "SHOW STATUS LIKE '%key_read_requests%'; SHOW STATUS LIKE '%key_reads%';" | mysql -N | awk '{print $2}' | tr -s '\n' ' ' | awk '{a=$1 / $2; if (a < 100) A="katastrophal" ; if (a >= 100) A="akzeptabel" ; if (a >= 1000) A="gut" ; if (a >= 10000) A="sehr gut"; print "Wert ist",A,"("a")"}'
 +  Wert ist sehr gut (12570.9)
 +  
 +  > echo "SHOW STATUS LIKE '%key_reads%'; SHOW STATUS LIKE '%key_read_requests%';" | mysql -t
 +  +---------------+---------+
 +  | Variable_name | Value   |
 +  +---------------+---------+
 +  | Key_reads     | 1583133 |
 +  +---------------+---------+
 +  +-------------------+-------------+
 +  | Variable_name     | Value       |
 +  +-------------------+-------------+
 +  | Key_read_requests | 19943598300 |
 +  +-------------------+-------------+
 +
 +//key_buffer_size 25% or more of the available RAM (The ratio of ''key_reads'' to ''key_read_requests'' should be as low as possible, 1:100 is the highest acceptable, 1:1000 is better, and 1:10 is terrible.)//
 +
  
/home/http/wiki/data/attic/mysql_tuning.1645705004.txt · Zuletzt geändert: von manfred