mysql之my.cnf

本文涉及的产品
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
RDS MySQL DuckDB 分析主实例,基础系列 4核8GB
RDS DuckDB + QuickBI 企业套餐,8核32GB + QuickBI 专业版
简介: 版权声明:欢迎转载,请注明沉默王二原创。 https://blog.csdn.net/qing_gee/article/details/49507817 mysql在安装完毕后,一般都要对my.cnf进行配置,以期mysql性能最大化。
版权声明:欢迎转载,请注明沉默王二原创。 https://blog.csdn.net/qing_gee/article/details/49507817

mysql在安装完毕后,一般都要对my.cnf进行配置,以期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

二、innodb_flush_log_at_trx_commit

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 scheduling issues. Because the flush to disk operation only occurs approximately once
per second, you can lose up to a second of transactions with any mysqld process crash.
• With a value of 2, the contents of the InnoDB log buffer are written to the log file after each transaction
commit and the log file is flushed to disk approximately once per second. Once-per-second flushing
is not 100% guaranteed to happen every second, due to process scheduling issues. Because the
flush to disk operation only occurs approximately once per second.

  1. innodb_flush_log_at_trx_commit=1,innodb的缓存会在事务提交或者每秒钟时都会进行磁盘的刷新操作,默认值。
  2. innodb_flush_log_at_trx_commit=2,innodb缓存会在提交事务时写入到事务日志但不会刷新磁盘,然后在每秒钟时进行磁盘刷新操作。
  3. innodb_flush_log_at_trx_commit=0,每秒钟时缓存写入日志,同时刷新磁盘。

根据我们的性能测试,发现在innodb_flush_log_at_trx_commit=2,数据的读写速度和1的时候有明显的提升。

三、innodb_buffer_pool_size、innodb_buffer_pool_instances

这两个参数,你必须得看看这个mysql:提升性能的最关键参数

四、binlog-format = MIXED

该种二进制日志模式是statement和row模式的结合体,不过需要注意的是mysql 5.7中的默认格式是STATEMENT,这会影响到服务端代码如java对事务的处理,非常关键,没有调试好的话,会导致事务不回滚。

In MySQL 5.7, the default format is STATEMENT.
You must have the SUPER privilege to set either the global or session binlog_format value.
The rules governing when changes to this variable take effect and how long the effect lasts are the same as for other MySQL server system variables. See Section 13.7.4, “SET Syntax”, for more information.
When MIXED is specified, statement-based replication is used, except for cases where only row-based replication is guaranteed to lead to proper results. For example, this happens when statements contain user-defined functions (UDF) or the UUID() function. An exception to this rule is that MIXED always uses statement-based replication for stored functions and triggers.

五、innodb_lock_wait_timeout = 20

事务回滚的时间间隔,定为20秒,是我们项目认为比较合理的值,另外可参见Transactional和mysql究竟有什么关系

六、transaction-isolation = REPEATABLE-READ

事务的隔离级别,对多事务的读写也有着关键的作用,可参见高性能mysql札记:事务

笑对现实的无奈,不能后退的时候,不再傍徨的时候,永远向前 路一直都在──陈奕迅《路一直都在》
本文出自:【沉默王二的博客

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
相关文章
|
存储 SQL 缓存
MySQL 配置文件 my.cnf / my.ini 逐行详解
充分理解 MySQL 配置文件中各个变量的意义对我们有针对性的优化 MySQL 数据库性能有非常大的意义。我们需要根据不同的数据量级,不同的生产环境情况对 MySQL 配置文件进行优化。Windows 和 Linux 下的 MySQL 配置文件的名字和存放位置都是不同的,WIndows 下 MySQL 配置文件是 `my.ini` 存放在 MySQL 安装目录的根目录下;Linux 下 MySQL 配置文件是 `my.cnf` 存放在 `/etc/my.cnf`、`/etc/mysql/my.cnf`。我们也可以通过 `find` 命令进行查找。
38260 2
|
安全 关系型数据库 MySQL
MySQL非root安装-初始化数据库时unknown variable ‘defaults-file=**/my.cnf‘
解决安装过程中出现的问题通常需要仔细地检查错误日志、配置文件和执行命令,保证各项配置设置的精确无误是顺利完成安装的关键。通过上述的步骤分析和解决方案,非root用户安装MySQL时遇到"unknown variable 'defaults-file=**/my.cnf'"的问题应该可以得到妥善的解决。
1368 0
|
存储 缓存 关系型数据库
Mysql/etc/my.cnf参数详解
以上只是 `/etc/my.cnf`中的部分参数,实际上,`/etc/my.cnf`中的参数非常多,可以根据具体的应用需求进行调整。
445 0
|
缓存 关系型数据库 MySQL
mysql5.7 mysql配置文件my.cnf 中 query_cache_min_res_unit 的优化
mysql5.7 mysql配置文件my.cnf 中 query_cache_min_res_unit 的优化
150 0
|
缓存 关系型数据库 MySQL
mysql 优化my.cnf
mysql 优化my.cnf
162 0
|
安全 关系型数据库 MySQL
MySQL my.cnf参数配置优化详解
MySQL my.cnf参数配置优化详解
309 0
|
SQL 存储 关系型数据库
MySQL配置文件my.cnf 优化
MySQL配置文件my.cnf 优化
500 0
|
关系型数据库 MySQL
MySQL:查找my.cnf配置文件的路径
MySQL:查找my.cnf配置文件的路径
546 0
|
监控 网络协议 关系型数据库
MySQL之my.cnf配置文件
MySQL之my.cnf配置文件
630 0
MySQL之my.cnf配置文件
|
监控 网络协议 关系型数据库
MySQL之my.cnf配置文件
MySQL之my.cnf配置文件
779 0
MySQL之my.cnf配置文件

推荐镜像

更多