前言:《mysql配置》,在centOS上安装完成mysql后,自然是要对mysql进行配置,对于mysql来说,my.cnf可是很重要的,相当于画龙点睛的作用呢。
经常不经意间就发现文章被扣到各式各样的网站上面,甚是可恶!
那么人生何处不爬虫,爬虫请标http://blog.csdn.net/qing_gee
见贤思齐焉,见不贤而内自省也!
特此说明,我这个配置文件内容是结合我项目实战经验多次总结出来的王道,对提升mysql性能有着关键性的作用,当然了,这要看你的项目是否需要这样做喽。
这个文件里面的配置项目很多,我就一一说明了(主要是俺其实有一些也不懂,千万要笑啊,我是真不懂,不过我有问过度娘!),
[client]
#no-beep
port=3306
[mysql]
default-character-set=utf8
socket = /var/lib/mysql/mysql.sock
[mysqld]
# The TCP/IP Port the MySQL Server will listen on
port=3306
socket = /var/lib/mysql/mysql.sock
character-set-server=utf8
#默认引擎设置为INNODB,这要看你的数据库是做什么用的
default-storage-engine=INNODB
#最大连接数,这个说实话,我没有测出来最合理的数值
max_connections = 500
#下面这两个参数就是禁用缓存查询,主要是因为我的数据库大量的写操作,所以设置了cache,反而会影响性能,也是基于理论上的,所以你大可不必相信。
query_cache_size=0
query_cache_type=0
#这几个数值,你千万要找度娘理论一下啊,我是说不清楚了
table_open_cache=2000
tmp_table_size=19M
thread_cache_size = 18
myisam_max_sort_file_size = 1G
myisam_sort_buffer_size=30M
key_buffer_size=8M
read_buffer_size = 512K
read_rnd_buffer_size = 1M
sort_buffer_size = 512k
#这个很重要了,对性能有着很大的影响,我会告诉你的。
innodb_flush_log_at_trx_commit=2
innodb_log_buffer_size=1M
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size=2G
innodb_buffer_pool_instances=1
#上面这两个参数对性能的作用我会论证给你的。
#这一块参数的作用我也忘的差不多了,所以度娘吧
innodb_log_file_size=48M
innodb_thread_concurrency=9
innodb_autoextend_increment=64
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
flush_time=0
join_buffer_size=256K
max_connect_errors=100
max_allowed_packet = 16M
open_files_limit=4161
table_definition_cache=1400
binlog_row_event_max_size=8K
#二进制的类型,这个有很大学问,稍候我也会告诉你的。
binlog-format = MIXED
#事务锁时间,这个同样学问很大。
innodb_lock_wait_timeout = 20
#事务锁级别,这个学问同样很大很大啊
transaction-isolation = REPEATABLE-READ
binlog_cache_size = 1M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
#这个参数就是设置二进制文件的路径的,注意啊,注意啊!
log_bin=mysql-bin
server_id = 1
[mysqldump]
max_allowed_packet = 16M
重点来了,下面这些内容,如果你没有看到,我觉得你错过了精彩,精彩啊,如果你错过了,我强烈抗议的,虽然抗议无效!
1.innodb_flush_log_at_trx_commit=2
Controls the balance between strict ACID compliance for commit operations, and higher performance
that is possible when commit-related I/O operations are rearranged and done in batches. You can
achieve better performance by changing the default value, but then you can lose up to a second of
transactions in a crash.
? The default value of 1 is required for full ACID compliance. With this value, the contents of the InnoDB
log buffer are written out to the log file at each transaction commit and the log file is flushed to disk.
? With a value of 0, the contents of the InnoDB log buffer are written to the log file approximately once
per second and the log file is flushed to disk. No writes from the log buffer to the log file are performed
at transaction commit. Once-per-second flushing is not 100% guaranteed to happen every second,
due to process schedulin