MySql my.ini详解

MySQL服务器实例配置文件模版

版本 1.0.1

安装MySQL为系统服务:mysqld --install MySQL41 --defaults-file="C:/Program Files/MySQL/MySQL Server 4.1/my.ini"

客户端部分[设置端口号]

port=3306

服务器端

port=3306设置端口号
basedir安装目录
datadir数据存放目录
default-character-set使用字符集
default-storage-engine存储引擎
max_connections最大连接数,(活动连接数*3/2+10)或者[MySQL可用内存]/512k
_available_memeory 空闲内存=可用内存-最大连接数*256k.
query_cache_size= 默认0,_available_memeory/10,或者8M
##
_available_memeory -= query_cache_size
_buffers_memeory=_available_memeory*7/10
_thread_buffers_memory=_available_memeory*3/10
_memory_per_thread每个线程内存=_thread_buffers_memory*_over_commit_factor/max_connections
table_cache=所有线程说打开的表默认256,或者max_connections*2
##
_buffers_memeory=_buffer_memeory - table_cache*8k
表暂时空间的大小,如果大于此值,就会写入磁盘中
_big_thread_buffers=<<<{:=[_memory_per_thread]*[_over_commit_factor2]}>>>
_tmp_table_size=<<<{:KM=16M,[_big_thread_buffers]}>>>
tmp_table_size=<<{:Km=[_tmp_table_size],[_memory]*10/100}>>

线程缓存

thread_cache=<<{:Rm=[_thread_cache],64}>>
innodb_buffer_pool_size 索引和原始数据缓存默认8M,大些比较好
日志文件大小innodb_log_file_size 默认10M, innodb_buffer_pool_size的25%到100%合适
线程并发度innodb_thread_concurrency=<<{:M=8,2*([CPUS]+[DISKS])}>>(innodb_thread_concurrency=<<{:M=8,2*([CPUS]+1)}>>)

 

 

my.ini配置建议:

table_cache=1024   
物理内存越大,设置就越大.默认为2402,调到512-1024最佳

innodb_additional_mem_pool_size=4M
默认为2M

innodb_flush_log_at_trx_commit=1
(设置为0就是等到innodb_log_buffer_size列队满后再统一储存,默认为1)

innodb_log_buffer_size=2M            
默认为1M

innodb_thread_concurrency=8         
你的服务器CPU有几个就设置为几,建议用默认一般为8

key_buffer_size=256M                     
默认为218         调到128最佳

tmp_table_size=64M                        
默认为16M        调到64-256最挂

read_buffer_size=4M                     
默认为64K

read_rnd_buffer_size=16M            
默认为256K

sort_buffer_size=32M                    
默认为256K

max_connections=1024               
默认为1210

thread_cache_size=120              
默认为60

query_cache_size=32M
————————————————————————————————–

以下是另一个的my.ini配置建议:

port=3306
default-character-set=latin1
default-storage-engine=INNODB
sql-mode=”STRICT_TRANS_TABLES,NO_AUTO_Create_USER,NO_ENGINE_SUBSTITUTION”

max_connections=120
query_cache_size=32M

#缓存数据表数量,设置这个参数可以参见系统状态中的 open_tables(表示当前打开的数据表总数) 和 opened_tables(表示所有打开的数据表总数)
table_cache=256

#临时表的大小
tmp_table_size=12M

#缓存可重用的线程数
thread_cache_size = 64

myisam_max_sort_file_size=100G
myisam_max_extra_sort_file_size=100G
myisam_sort_buffer_size=64M

#这对MyISAM表来说非常重要。如果只是使用MyISAM表,可以把它设置为可用内存的 30-40%。合理的值取决于索引大小、数据量以及负载 — #记住,MyISAM表会使用操作系统的缓存来缓存数据,因此需要留出部分内存给它们,很多情况下数据比索引大多了。
key_buffer_size=128M

read_buffer_size=1M
read_rnd_buffer_size=512K
sort_buffer_size=1M

#这对innodb表来说非常重要
innodb_buffer_pool_size = 256M

#这取决于你需要的回复速度.128M这个数值是适当的恢复时间和良好性能之间的一个好的平衡.
innodb_log_file_size = 128M

#大多数情况4M足够,除非正将很大的blob数据导入到Innodb中可以增加一点.
innodb_log_buffer_size=4M

#这个值取决于你的程序,可能高或者低.8是代表起始值.
innodb_thread_concurrency=8

innodb_additional_mem_pool_size=100M

#如果你不是很关心ACID,可以容许在系统完全crash的情况下丢失最后一两秒的事务,那么可以设置这个值.它可以极大的提高”短”的写事务的效率.
innodb_flush_log_at_trx_commit=2


注意:
很多情况需要具体情况具体分析
1>如果Key_reads太大,则应该把my.cnf中Key_buffer_size变大,保持Key_reads/Key_read_requests至少1/100以上,越小越好。
2>如果Qcache_lowmem_prunes很大,就要增加Query_cache_size的值

 

==================================================================================

 



这是MY.INI文件:

# Example MySQL config file for large systems. 
  
# 
  
# This is for a large system with memory = 512M where the system runs mainly 
  
# MySQL. 
  
# 
  
# You can copy this file to 
  
# /etc/my.cnf to set global options, 
  
# mysql-data-dir/my.cnf to set server-specific options (in this 
  
# installation this directory is /usr/local/var) or 
  
# ~/.my.cnf to set user-specific options. 
  
# 
  
# In this file, you can use all long options that a program supports. 
  
# If you want to know which options a program supports, run the program 
  
# with the "--help" option. 
  

# The following options will be passed to all MySQL clients 
  
[client] 
  
#password        = your_password 
  
port                = 3306 
  
socket                = /tmp/mysql.sock 
  

# Here follows entries for some specific programs 
  

# The MySQL server 
  
[mysqld] 
  
port                = 3306 
  
socket                = /tmp/mysql.sock 
  
skip-locking 
  
key_buffer = 256M 
  
max_allowed_packet = 1M 
  
table_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 
  
# Try number of CPU's*2 for thread_concurrency 
  
thread_concurrency = 8 
  

# Don't listen on a TCP/IP port at all. This can be a security enhancement, 
  
# if all processes that need to connect to mysqld run on the same host. 
  
# All interaction with mysqld must be made via Unix sockets or named pipes. 
  
# Note that using this option without enabling named pipes on Windows 
  
# (via the "enable-named-pipe" option) will render mysqld useless! 
  
# 
  
#skip-networking 
  

# Replication Master Server (default) 
  
# binary logging is required for replication 
  
log-bin=mysql-bin 
  

# required unique id between 1 and 2^32 - 1 
  
# defaults to 1 if master-host is not set 
  
# but will not function as a master if omitted 
  
server-id        = 1 
  

# Replication Slave (comment out master section to use this) 
  
# 
  
# To configure this host as a replication slave, you can choose between 
  
# two methods : 
  
# 
  
# 1) Use the CHANGE MASTER TO command (fully described in our manual) - 
  
#    the syntax is: 
  
# 
  
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>, 
  
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ; 
  
# 
  
#    where you replace <host>, <user>, <password> by quoted strings and 
  
#    <port> by the master's port number (3306 by default). 
  
# 
  
#    Example: 
  
# 
  
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306, 
  
#    MASTER_USER='joe', MASTER_PASSWORD='secret'; 
  
# 
  
# OR 
  
# 
  
# 2) Set the variables below. However, in case you choose this method, then 
  
#    start replication for the first time (even unsuccessfully, for example 
  
#    if you mistyped the password in master-password and the slave fails to 
  
#    connect), the slave will create a master.info file, and any later 
  
#    change in this file to the variables' values below will be ignored and 
  
#    overridden by the content of the master.info file, unless you shutdown 
  
#    the slave server, delete master.info and restart the slaver server. 
  
#    For that reason, you may want to leave the lines below untouched 
  
#    (commented) and instead use CHANGE MASTER TO (see above) 
  
# 
  
# required unique id between 2 and 2^32 - 1 
  
# (and different from the master) 
  
# defaults to 2 if master-host is set 
  
# but will not function as a slave if omitted 
  
#server-id      = 2 
  
# 
  
# The replication master for this slave - required 
  
#master-host    =  <hostname> 
  
# 
  
# The username the slave will use for authentication when connecting 
  
# to the master - required 
  
#master-user    =  <username> 
  
# 
  
# The password the slave will authenticate with when connecting to 
  
# the master - required 
  
#master-password =  <password> 
  
# 
  
# The port the master is listening on. 
  
# optional - defaults to 3306 
  
#master-port    =  <port> 
  
# 
  
# binary logging - not required for slaves, but recommended 
  
#log-bin=mysql-bin 
  

# Point the following paths to different dedicated disks 
  
#tmpdir                = /tmp/                
  
#log-update        = /path-to-dedicated-directory/hostname 
  

# Uncomment the following if you are using BDB tables 
  
#bdb_cache_size = 64M 
  
#bdb_max_lock = 100000 
  

# Uncomment the following if you are using InnoDB tables 
  
#innodb_data_home_dir = /usr/local/var/ 
  
#innodb_data_file_path = ibdata1:10M:autoextend 
  
#innodb_log_group_home_dir = /usr/local/var/ 
  
#innodb_log_arch_dir = /usr/local/var/ 
  
# You can set .._buffer_pool_size up to 50 - 80 % 
  
# of RAM but beware of setting memory usage too high 
  
#innodb_buffer_pool_size = 256M 
  
#innodb_additional_mem_pool_size = 20M 
  
# Set .._log_file_size to 25 % of buffer pool size 
  
#innodb_log_file_size = 64M 
  
#innodb_log_buffer_size = 8M 
  
#innodb_flush_log_at_trx_commit = 1 
  
#innodb_lock_wait_timeout = 50 
  
set-variable=max_connections=10000 
  

[mysqldump] 
  
quick 
  
max_allowed_packet = 16M 
  

[mysql] 
  
no-auto-rehash 
  
# Remove the next comment character if you are not familiar with SQL 
  
#safe-updates 
  

[isamchk] 
  
key_buffer = 128M 
  
sort_buffer_size = 128M 
  
read_buffer = 2M 
  
write_buffer = 2M 
  

[myisamchk] 
  
key_buffer = 128M 
  
sort_buffer_size = 128M 
  
read_buffer = 2M 
  
write_buffer = 2M 
  

[mysqlhotcopy] 
  
interactive-timeout