天天看點

mysql性能最大化

[client]

#passwd = your_passwd

port = 3306

socket = /data/mysql/mysql.sock

[mysqld]

#global settings

port = 3306

socket = /data/mysql/mysql.sock

basedir=/usr/local/mysql

tmpdir=/data/mysql

datadir=/data/mysql

pid-file=/data/mysql/rongzhong.pid

#跳過外部鎖定 隻對MyISAM

skip-external-locking

#禁用tcp socket連接配接,隻能使用unix/linux socket連接配接

skip_networking

#禁用DNS解析,提高連接配接速度

skip_name_resolve

#跳過授權表,忘記root密碼時使用

#skip-grant-tables

#預設存儲引擎

#default-storage-engine=MyISAM/INNODB

#預設字元集

character_set_server=utf8

#最大連接配接數

max_connections=20480

#最大單使用者連接配接數

max_user_connections=1024

#伺服器關閉一個互動連接配接前等待的秒數,預設28800

interactive_timeout=7200

#線程緩存數,直接利用空閑連接配接來建立新連接配接,1G  —> 8 2G  —> 16 3G  —> 32 >3G  —> 64

#短連接配接較多的情況下可以适當增加該值

thread_cache_size=64

#單個線程(連接配接)進行資料排序(eg: order/group by)時的buffer,連接配接建立時一次性配置設定,預設2M,當 Sort_merge_passes較大時可增加該值

sort_buffer_size=2M

#對沒有索引的表進行join操作時的buffer,預設256K,連接配接建立時一次性配置設定

join_buffer_size=262144

#指定連接配接偵聽隊列的大小,該值超過OS的tcp_max_syn_backlog/somaxconn時無效,推薦設定為小于512的整數

back_log=512

#table_open_cache中歲多能打開的表數

table_open_cache = 256

#一次消息傳輸量的最大值,是net_buffer_length的最大值

max_allowed_packet=8M

#bin-log

#打開二進制日志

log-bin=mysql-bin

log-bin-index=mysql-bin.index

#日志格式,可選row/statement/mixed,預設statement,推薦mixed

binlog_format=mixed

#一個binlog的最大值

max_binlog_size=1G

#對單個連接配接的binlog緩存大小,預設1M

binlog_cache_size=2M

#binlog cache的總大小

max_binlog_cache_size=2G

#sync_binlog may be 0 or 1

#binlog是否進行磁盤同步,為0時交給OS,為1:事物結束立即同步,IO損耗大

sync_binlog=0

#slow-log

#開啟slow log

slow-query-log=1

#指定慢查詢的時長

long-query-time=2

#路徑

slow-query-log-file=/data/mysql/slowlog/slow.log

#未使用索引的查詢也記錄到slow log中

log_queries_not_using_indexes=1

#query cache

#啟用query cache

query_cache_type=1

#存放單條query cache的最大值,預設1M

query_cache_limit=1M

#存放單條query cache的最小值,預設4K

query_cache_min_res_unit=4096

#query的最大值

query_cache_size=256M

#MyISAM

#索引緩存大小,公式:Key_Size = key_number * (key_length+4)/0.67

key_buffer_size=128M

#單個線程進行順序讀取時的緩存,預設128K

read_buffer_size=2M

#單個線程進行随機讀取時的緩存,預設256K

read_rnd_buffer_size = 4M

#重建索引時允許的最大緩存大小,預設8M

myisam_sort_buffer_size = 64M

#指定索引緩存中block大小,預設1K

key_cache_block_size=1024

#禁止索引的單條重新整理

delay_key_write=1

#innodb

#啟用獨立的表空間

#innodb_file_per_table=1

#設定innodb記憶體緩沖區大小,在純mysql環境下,推薦設定為伺服器記憶體的60~80%

innodb_buffer_pool_size =8G

#設定OS能進入innodb核心的線程數,推薦2*(CPU核心數+磁盤數)

innodb_thread_concurrency=16

#設定innodb的io行為,可選值fsync/O_DSYNC/O_DIRECT 推薦O_DIRECT提高随機寫效率

innodb_flush_method=O_DIRECT

#設定mysql主程序每秒鐘向磁盤刷入的髒頁數,預設值200

#For systems with individual 5400 RPM or 7200 RPM drives, you might lower the value to the former default of 100

innodb_io_capacity=100

#設定寫髒頁的線程數

innodb_write_io_threads = 8

#設定從磁盤讀檔案塊的線程數

innodb_read_io_threads = 8

#設定事物日志緩沖區大小

#設定事物日志緩沖區大小

innodb_log_buffer_size=8M

#log thread向磁盤同步日志的方式,可選值為0/1/2

#0: 每秒鐘重新整理  1:每次事物送出後都重新整理 2:交給OS來同步

innodb_flush_log_at_trx_commit =0

#資料庫字典資訊和表結構空間

innodb_additional_mem_pool_size =16M

#啟用Double write Buffer區域,保證資料完整性,但消耗IO

innodb_doublewrite=1

[mysqldump]

# Do not buffer the whole result set in memory before writing it to file. Required for dumping very large tables

quick

max_allowed_packet = 16M

[mysql]

no-auto-rehash

[myisamchk]

key_buffer_size = 512M

sort_buffer_size = 512M

read_buffer = 8M

write_buffer = 8M

[mysqlhotcopy]

interactive-timeout

[mysqld_safe]

# Increase the amount of open files allowed per process. Warning: Make

# sure you have set the global system limit high enough! The high value

# is required for a large number of opened tables

open-files-limit = 8192