Archive pour la catégorie 'MySQL'

Purger automatiquement les vieux bin logs sous MySQL

Friday 11 April 2008

Pour ce faire, il faut rajouter la ligne expire_logs_days = 10 dans votre fichier de configuration de MySQL (my.ini ou my.cnf). 10 représente le nombre de jours au delà duquel les bin-logs seront supprimés.

Activer le slow query log sous MySQL

Friday 11 April 2008

Il n’est pas possible d’activer l’option log-slow-queries à chaud malheureusement.

long_query_time permet de spécifier la durée minimale à partir de laquelle une requête est stockée dans le slow query log. Cette valeur doit être comprise entre 1 et 10 secondes

Il faut dès lors modifier my.cnf ou my.ini et rajouter :

long_query_time permet de spécifier la durée minimale à partir de laquelle une requête est stockée dans le slow query log. Cette valeur doit être comprise entre 1 et 10 secondes

long_query_time         = 10
log-slow-queries        = /var/log/mysql/mysql-slow.log

Labo pour apprendre à optimiser les requêtes MySQL

Friday 11 January 2008

A télécharger sur :
http://jpipes.com/presentations/target-practice/target-practice-workbook.pdf.

Trouver les 10 plus mauvais index dans votre base de donnée MySQL

Friday 11 January 2008
SELECT
t.TABLE_SCHEMA AS `db`
, t.TABLE_NAME AS `table`
, s.INDEX_NAME AS `inde name`
, s.COLUMN_NAME AS `field name`
, s.SEQ_IN_INDEX `seq in index`
, s2.max_columns AS `# cols`
, s.CARDINALITY AS `card`
, t.TABLE_ROWS AS `est rows`
, ROUND(((s.CARDINALITY / IFNULL(t.TABLE_ROWS, 0.01)) * 100), 2) AS `sel %`
FROM INFORMATION_SCHEMA.STATISTICS s
INNER JOIN INFORMATION_SCHEMA.TABLES t
ON s.TABLE_SCHEMA = t.TABLE_SCHEMA
AND s.TABLE_NAME = t.TABLE_NAME
INNER JOIN (
SELECT TABLE_SCHEMA, TABLE_NAME, INDEX_NAME, MAX(SEQ_IN_INDEX) AS max_columns
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA != 'mysql'
GROUP BY TABLE_SCHEMA, TABLE_NAME, INDEX_NAME
) AS s2
ON s.TABLE_SCHEMA = s2.TABLE_SCHEMA
AND s.TABLE_NAME = s2.TABLE_NAME
AND s.INDEX_NAME = s2.INDEX_NAME
/* Filter out the mysql system DB */
WHERE t.TABLE_SCHEMA != 'mysql'
/* Only tables with some rows */
AND t.TABLE_ROWS > 10
/* Need at least one non-NULL value in the field */
AND s.CARDINALITY IS NOT NULL
/* unique indexes are perfect anyway */
AND (s.CARDINALITY / IFNULL(t.TABLE_ROWS, 0.01)) < 1.00
/* DESC for best non-unique indexes */
ORDER BY `sel %`, s.TABLE_SCHEMA, s.TABLE_NAME
LIMIT 10;

A essayer de toute urgence si vous avez des problèmes de performance.

Source : Jay Pipes

Changer les paramètres de configuration de MySQL à chaud

Friday 11 January 2008

Eh oui, il est possible de changer certains paramètres de MySQL à chaud.
Bien pratique quand il est nécessaire d’ajuster certains paramètres lorsque le serveur ne peut être arrêté souvent !

Le site de pythian nous donne un tableau comprenant ceux qui peuvent être changés à chaud et ceux qui ne le sont pas.

Variable Name Variable Type SET OFFLINE ONLY SET GLOBAL SET SESSION
auto_increment_increment numeric OFFLINE
auto_increment_offset numeric OFFLINE
autocommit boolean SESSION
automatic_sp_privileges boolean GLOBAL
back_log numeric OFFLINE
basedir string OFFLINE
bdb_cache_size numeric OFFLINE
bdb_home string OFFLINE
bdb_log_buffer_size numeric OFFLINE
bdb_logdir string OFFLINE
bdb_max_lock numeric OFFLINE
bdb_shared_data boolean OFFLINE
bdb_tmpdir string OFFLINE
big_tables boolean SESSION
binlog_cache_size numeric GLOBAL
bulk_insert_buffer_size numeric GLOBAL SESSION
character_set_client string GLOBAL SESSION
character_set_connection string GLOBAL SESSION
character_set_database string OFFLINE
character_set_filesystem string GLOBAL SESSION
character_set_results string GLOBAL SESSION
character_set_server string GLOBAL SESSION
character_set_system string OFFLINE
character_sets_dir string OFFLINE
collation_connection string GLOBAL SESSION
collation_database string OFFLINE
collation_server string GLOBAL SESSION
completion_type numeric GLOBAL SESSION
concurrent_insert numeric GLOBAL
connect_timeout numeric GLOBAL
datadir string OFFLINE
date_format OFFLINE
datetime_format OFFLINE
default_week_format numeric GLOBAL SESSION
delay_key_write OFF | ON | ALL GLOBAL
delayed_insert_limit numeric GLOBAL
delayed_insert_timeout numeric GLOBAL
delayed_queue_size numeric GLOBAL
div_precision_increment numeric GLOBAL SESSION
engine_condition_pushdown boolean GLOBAL SESSION
error_count numeric SESSION
expire_logs_days numeric GLOBAL
flush boolean GLOBAL
flush_time numeric GLOBAL
foreign_key_checks boolean SESSION
ft_boolean_syntax string GLOBAL
ft_max_word_len numeric OFFLINE
ft_min_word_len numeric OFFLINE
ft_query_expansion_limit numeric OFFLINE
ft_stopword_file string OFFLINE
group_concat_max_len numeric GLOBAL SESSION
have_archive boolean OFFLINE
have_bdb boolean OFFLINE
have_blackhole_engine boolean OFFLINE
have_compress boolean OFFLINE
have_crypt boolean OFFLINE
have_csv boolean OFFLINE
have_dynamic_loading boolean OFFLINE
have_example_engine boolean OFFLINE
have_federated_engine boolean OFFLINE
have_geometry boolean OFFLINE
have_innodb boolean OFFLINE
have_isam boolean OFFLINE
have_merge_engine boolean OFFLINE
have_ndbcluster boolean OFFLINE
have_openssl boolean OFFLINE
have_query_cache boolean OFFLINE
have_raid boolean OFFLINE
have_rtree_keys boolean OFFLINE
have_symlink boolean OFFLINE
init_connect string OFFLINE
init_file string OFFLINE
init_slave string OFFLINE
innodb_additional_mem_pool_size numeric OFFLINE
innodb_autoextend_increment numeric GLOBAL
innodb_buffer_pool_awe_mem_mb numeric OFFLINE
innodb_buffer_pool_size numeric OFFLINE
innodb_checksums boolean OFFLINE
innodb_commit_concurrency numeric GLOBAL
innodb_concurrency_tickets numeric GLOBAL
innodb_data_file_path string OFFLINE
innodb_data_home_dir string OFFLINE
innodb_doublewrite boolean OFFLINE
innodb_fast_shutdown 0,1 or 2 OFFLINE
innodb_file_io_threads numeric OFFLINE
innodb_file_per_table boolean OFFLINE
innodb_flush_log_at_trx_commit 0,1 or 2 OFFLINE
innodb_flush_method Enum OFFLINE
innodb_force_recovery 1 to 6 OFFLINE
innodb_lock_wait_timeout numeric OFFLINE
innodb_locks_unsafe_for_binlog boolean OFFLINE
innodb_log_arch_dir string OFFLINE
innodb_log_archive OFFLINE
innodb_log_buffer_size numeric OFFLINE
innodb_log_file_size numeric OFFLINE
innodb_log_files_in_group numeric OFFLINE
innodb_log_group_home_dir string OFFLINE
innodb_max_dirty_pages_pct numeric GLOBAL
innodb_max_purge_lag numeric GLOBAL
innodb_mirrored_log_groups numeric OFFLINE
innodb_open_files numeric OFFLINE
innodb_support_xa boolean GLOBAL SESSION
innodb_sync_spin_loops numeric GLOBAL
innodb_table_locks boolean GLOBAL SESSION
innodb_thread_concurrency numeric GLOBAL
innodb_thread_sleep_delay numeric GLOBAL
interactive_timeout numeric GLOBAL SESSION
join_buffer_size numeric GLOBAL SESSION
key_buffer_size numeric GLOBAL
key_cache_age_threshold numeric OFFLINE
key_cache_block_size numeric OFFLINE
key_cache_division_limit 1 to 100 OFFLINE
language string OFFLINE
large_files_support boolean OFFLINE
large_page_size numeric OFFLINE
large_pages boolean OFFLINE
lc_time_names string GLOBAL SESSION
license string OFFLINE
local_infile boolean GLOBAL
locked_in_memory boolean OFFLINE
log boolean OFFLINE
log_bin boolean OFFLINE
log_bin_trust_function_creators boolean GLOBAL
log_error string OFFLINE
log_queries_not_using_indexes boolean GLOBAL
log_slave_updates boolean OFFLINE
log_slow_queries boolean OFFLINE
log_warnings numeric GLOBAL
long_query_time numeric GLOBAL SESSION
low_priority_updates boolean GLOBAL SESSION
lower_case_file_system boolean OFFLINE
lower_case_table_names numeric OFFLINE
max_allowed_packet numeric GLOBAL SESSION
max_binlog_cache_size numeric GLOBAL
max_binlog_size numeric GLOBAL
max_connect_errors numeric GLOBAL
max_connections numeric GLOBAL
max_delayed_threads numeric GLOBAL
max_error_count numeric GLOBAL SESSION
max_heap_table_size numeric GLOBAL SESSION
max_insert_delayed_threads numeric GLOBAL
max_join_size numeric GLOBAL SESSION
max_length_for_sort_data numeric OFFLINE
max_prepared_stmt_count numeric GLOBAL
max_relay_log_size numeric GLOBAL
max_seeks_for_key numeric GLOBAL SESSION
max_sort_length numeric GLOBAL SESSION
max_sp_recursion_depth numeric OFFLINE
max_tmp_tables numeric GLOBAL SESSION
max_user_connections numeric GLOBAL
max_write_lock_count numeric GLOBAL
multi_range_count numeric GLOBAL SESSION
myisam_data_pointer_size numeric GLOBAL
myisam_max_sort_file_size numeric GLOBAL SESSION
myisam_recover_options boolean OFFLINE
myisam_repair_threads numeric GLOBAL SESSION
myisam_sort_buffer_size numeric GLOBAL SESSION
myisam_stats_method enum GLOBAL SESSION
net_buffer_length numeric GLOBAL SESSION
net_read_timeout numeric GLOBAL SESSION
net_retry_count numeric GLOBAL SESSION
net_write_timeout numeric GLOBAL SESSION
new boolean OFFLINE
old_passwords boolean GLOBAL SESSION
open_files_limit numeric OFFLINE
optimizer_prune_level numeric GLOBAL SESSION
optimizer_search_depth numeric GLOBAL SESSION
pid_file string OFFLINE
port numeric OFFLINE
preload_buffer_size numeric GLOBAL SESSION
prepared_stmt_count numeric OFFLINE
protocol_version numeric OFFLINE
query_alloc_block_size numeric GLOBAL SESSION
query_cache_limit numeric GLOBAL
query_cache_min_res_unit numeric OFFLINE
query_cache_size numeric GLOBAL
query_cache_type enumeration GLOBAL SESSION
query_cache_wlock_invalidate boolean GLOBAL SESSION
query_prealloc_size numeric GLOBAL SESSION
range_alloc_block_size numeric GLOBAL SESSION
read_buffer_size numeric GLOBAL SESSION
read_only numeric GLOBAL
read_rnd_buffer_size numeric GLOBAL SESSION
relay_log_purge boolean OFFLINE
relay_log_space_limit numeric OFFLINE
rpl_recovery_rank numeric GLOBAL
secure_auth boolean GLOBAL
server_id numeric GLOBAL
skip_external_locking boolean OFFLINE
skip_networking boolean OFFLINE
skip_show_database boolean OFFLINE
slave_compressed_protocol boolean GLOBAL
slave_load_tmpdir string OFFLINE
slave_net_timeout numeric GLOBAL
slave_skip_errors boolean OFFLINE
slave_transaction_retries numeric GLOBAL
slow_launch_time numeric GLOBAL
socket string OFFLINE
sort_buffer_size numeric GLOBAL SESSION
sql_auto_is_null boolean SESSION
sql_big_selects boolean SESSION
sql_big_tables boolean SESSION
sql_buffer_result boolean SESSION
sql_log_bin boolean SESSION
sql_log_off boolean SESSION
sql_log_update boolean SESSION
sql_low_priority_updates boolean GLOBAL SESSION
sql_max_join_size numeric GLOBAL SESSION
sql_mode enumeration GLOBAL SESSION
sql_notes boolean SESSION
sql_quote_show_create boolean SESSION
sql_safe_updates boolean SESSION
sql_select_limit numeric SESSION
sql_slave_skip_counter numeric GLOBAL
sql_warnings boolean SESSION
ssl_ca string OFFLINE
ssl_capath string OFFLINE
ssl_cert string OFFLINE
ssl_cipher string OFFLINE
ssl_key string OFFLINE
storage_engine enumeration GLOBAL SESSION
sync_binlog numeric GLOBAL
sync_frm boolean GLOBAL
system_time_zone string OFFLINE
table_cache numeric GLOBAL
table_lock_wait_timeout numeric OFFLINE
table_type enumeration GLOBAL SESSION
thread_cache_size numeric GLOBAL
thread_stack numeric OFFLINE
time_format OFFLINE
time_zone string GLOBAL SESSION
timed_mutexes boolean OFFLINE
tmp_table_size enumeration GLOBAL SESSION
tmpdir string OFFLINE
transaction_alloc_block_size numeric GLOBAL SESSION
transaction_prealloc_size numeric GLOBAL SESSION
tx_isolation enumeration GLOBAL SESSION
updatable_views_with_limit enumeration GLOBAL SESSION
version string OFFLINE
version_bdb string OFFLINE
version_comment string OFFLINE
version_compile_machine string OFFLINE
version_compile_os numeric OFFLINE
wait_timeout numeric GLOBAL SESSION

Source : http://www.pythian.com/blogs/447/table-of-mysql-parameters

Optimisation MySQL pour hautes performances

Friday 11 January 2008

C’est simple, je n’ai jamais vu de meilleur résumé des conseils concernant l’optimisation de MySQL.
Jay Pipes a fait une conférence au PHP 2007. A lire de toute urgence !!!

Optimiser la configuration de MySQL grâce à MySQL Tuner

Thursday 10 January 2008

Mysql Tuner est un script écrit en perl qui permet de mettre le doigt sur les paramètres à changer sur une base de donnée pour qu’elle fonctionne de manière optimale point de vue fiabilité et performance.

Voici un exemple de sortie de ce script fort utile :

# ./mysqltuner.pl
     MySQL High-Performance Tuner - Major Hayden
     Bug reports, feature requests, and downloads at mysqltuner.com
     Run with ‘–help’ for additional options and output filtering
[OK] Currently running supported MySQL version 5.0.44-log
——– General Statistics ————————————————–
[–] Up for: 15s (15 q [1.000 qps], 8 conn, TX: 20K, RX: 894)
[OK] Maximum possible memory usage: 318.7M (63% of installed RAM)
[OK] Slow queries: 0%
[OK] Highest usage of available connections: 2%
[!!] Key buffer size / total MyISAM indexes: 8.0M/64.8M
[!!] Query cache is disabled
[OK] Temporary tables created on disk: 19%
[!!] Thread cache hit rate: 12%
[OK] Table cache hit rate: 80%
[OK] Open file limit used: 4%
[OK] Table locks acquired immediately: 100%
——– Recommendations —————————————————–
General recommendations:
     MySQL started within last 24 hours - recommendations may be inaccurate
Variables to increase:
     key_buffer_size (> 64.8M)
     query_cache_size (>= 8M)
Variables to decrease:
     long_query_time (<= 5)
     max_seeks_for_key (<= 100)

Avec ces informations, il ne vous reste plus qu’à modifier les paramètres de my.cnf ou my.ini.

ERROR 3 (HY000): Error writing file ‘./madb/#sql-1d3d_40.frm’ (Errcode: 28)

Wednesday 12 December 2007

Partition pleine, il faut faire du ménage

Vidéo sur l’optimisation des requêtes sous MySQL

Thursday 11 January 2007

Réalisé par Jay Pipes, le co-autheur de Pro Mysql :

Ajouter une colonne après ou avant une autre colonne dans une table existante

Thursday 4 January 2007

Après un colonne définie :

SQL:
  1. ALTER TABLE matable ADD COLUMN macollone VARCHAR(5) AFTER lacolonneprecedente

En premier :

SQL:
  1. ALTER TABLE matable ADD COLUMN macollone VARCHAR(5) FIRST

PS : il n’y a pas de before :-)