前言

对于MySQL的理解,我认为很多性能优化工作、主从主主复制都是在调整参数,来适应不同时期不同数量级的数据。

故,理解透彻my.cnf里的参数是永恒的话题;只有理解透彻了参数设置,才能在某些方面对数据库进行调优。

前几天刚接手一个MySQL数据,操作系统为Ubuntu 16.04.5 LTS, 数据库版本为5.7.23-0ubuntu0.16.04.1(APT方式安装的MySQL)。这个操作系统下的MySQL的配置文件my.cnf很多地方都让人有点不适应(跟之前的MySQL环境有些出入,之前都是维护RHEL、CentOS等操作系统环境下的MySQL)。

遂研究总结了一下。具体如下所示:

root@mylnx12:~# find / -name "my.cnf"/etc/alternatives/my.cnf/etc/mysql/my.cnf/var/lib/dpkg/alternatives/my.cnfroot@mylnx12:~# locate my.cnf/etc/alternatives/my.cnf/etc/mysql/my.cnf/etc/mysql/my.cnf.fallback/var/lib/dpkg/alternatives/my.cnfroot@mylnx12:~# mysql --help | grep my.cnf      order of preference, my.cnf, $MYSQL_TCP_PORT,/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf root@mylnx12:~# mysqld --verbose --help | grep -A 1 'Default options'Default options are read from the following files in the given order:/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf 
root@mylnx12:~# ls -lrt /etc/alternatives/my.cnflrwxrwxrwx 1 root root 20 Sep 28 16:28 /etc/alternatives/my.cnf -> /etc/mysql/mysql.cnf
root@mylnx12:~# cat /var/lib/dpkg/alternatives/my.cnfauto/etc/mysql/my.cnf /etc/mysql/my.cnf.fallback100/etc/mysql/mysql.cnf200
root@mylnx12:~# cat /etc/mysql/my.cnf## The MySQL database server configuration file.## You can copy this to one of:# - "/etc/mysql/my.cnf" to set global options,# - "~/.my.cnf" to set user-specific options.# # One can use all long options that the program supports.# Run program with --help to get a list of available options and with# --print-defaults to see which it would actually understand and use.## For explanations see# http://dev.mysql.com/doc/mysql/en/server-system-variables.html ## * IMPORTANT: Additional settings that can override those from this file!#  The files must end with '.cnf', otherwise they'll be ignored.# !includedir /etc/mysql/conf.d/!includedir /etc/mysql/mysql.conf.d/

!includedir /etc/mysql/conf.d/

#表示包含/etc/mysql/conf.d/这个路径下面的配置文件,前提是必须以为.cnf为后缀

!includedir /etc/mysql/mysql.conf.d/

#表示包含/etc/mysql/mysql.conf.d/这个路径下面的配置文件,前提是必须以为.cnf为后缀

其实MySQL的相关配置都位于mysqld.cnf(/etc/mysql/mysql.conf.d/mysqld.cnf)下面。使用相关参数测试了一下,确实都能生效。这种设置确实有点让刚接触的人有点不适应。暂时先总结到此!

root@mylnx12:~# cd /etc/mysql/mysql.conf.d/root@mylnx12:/etc/mysql/mysql.conf.d# ls -lrttotal 8-rw-r--r-- 1 root root  21 Feb 4 2017 mysqld_safe_syslog.cnf-rw-r--r-- 1 root root 3148 Oct 6 23:34 mysqld.cnfroot@mylnx12:/etc/mysql/mysql.conf.d# cat mysqld.cnf## The MySQL database server configuration file.## You can copy this to one of:# - "/etc/mysql/my.cnf" to set global options,# - "~/.my.cnf" to set user-specific options.# # One can use all long options that the program supports.# Run program with --help to get a list of available options and with# --print-defaults to see which it would actually understand and use.## For explanations see# http://dev.mysql.com/doc/mysql/en/server-system-variables.html # This will be passed to all mysql clients# It has been reported that passwords should be enclosed with ticks/quotes# escpecially if they contain "#" chars...# Remember to edit /etc/mysql/debian.cnf when changing the socket location. # Here is entries for some specific programs# The following values assume you have at least 32M ram [mysqld_safe]socket     = /var/run/mysqld/mysqld.socknice      = 0 [mysqld]## * Basic Settings#user      = mysqlpid-file    = /var/run/mysqld/mysqld.pidsocket     = /var/run/mysqld/mysqld.sockport      = 3306basedir     = /usrdatadir     = /var/lib/mysqltmpdir     = /tmplc-messages-dir = /usr/share/mysqlskip-external-lockinglog_bin    = mylnx12_binserver_id   = 0character-set-server=utf8mb4collation-server=utf8mb4_general_ci ## Instead of skip-networking the default is now to listen only on# localhost which is more compatible and is not less secure.bind-address      = 10.21.6.7## * Fine Tuning#key_buffer_size     = 16Mmax_allowed_packet   = 100Mthread_stack      = 192Kthread_cache_size    = 8# This replaces the startup script and checks MyISAM tables if needed# the first time they are touchedmyisam-recover-options = BACKUP#max_connections    = 100#table_cache      = 64#thread_concurrency   = 10## * Query Cache Configuration#query_cache_limit    = 1Mquery_cache_size    = 16M## * Logging and Replication## Both location gets rotated by the cronjob.# Be aware that this log type is a performance killer.# As of 5.1 you can enable the log at runtime!#general_log_file    = /var/log/mysql/mysql.log#general_log       = 1## Error log - should be very few entries.#log_error = /var/log/mysql/error.log## Here you can see queries with especially long duration#log_slow_queries    = /var/log/mysql/mysql-slow.log#long_query_time = 2#log-queries-not-using-indexes## The following can be used as easy to replay backup logs or for replication.# note: if you are setting up a replication slave, see README.Debian about#    other settings you may need to change.#server-id       = 1#log_bin            = /var/log/mysql/mysql-bin.logexpire_logs_days    = 10max_binlog_size  = 100M#binlog_do_db      = include_database_name#binlog_ignore_db    = include_database_name## * InnoDB## InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.# Read the manual for more InnoDB related options. There are many!## * Security Features## Read the manual, too, if you want chroot!# chroot = /var/lib/mysql/## For generating SSL certificates I recommend the OpenSSL GUI "tinyca".## ssl-ca=/etc/mysql/cacert.pem# ssl-cert=/etc/mysql/server-cert.pem#: ssl-key=/etc/mysql/server-key.pem

更多相关文章

  1. MySQL系列多表连接查询92及99语法示例详解教程
  2. mybatisplus的坑 insert标签insert into select无参数问题的解决
  3. Python技巧匿名函数、回调函数和高阶函数
  4. python list.sort()根据多个关键字排序的方法实现
  5. android中文api(89)——ViewManager
  6. Andorid Dialog 示例【慢慢更新】
  7. Android调用天气预报的WebService简单例子
  8. Android(安卓)Activity的启动
  9. MTK Android(安卓)Driver:led

随机推荐

  1. JS读取XML数据的示例代码分享
  2. 具体介绍使用XmlReader读取xml文件的代码
  3. 详解XML中Node和Element区别的示例代码
  4. Xml序列化的图文代码详解
  5. XML学习(三) js保存xml的示例代码分享
  6. XML串行化的示例代码分享
  7. 详细介绍XML操作总结的示例代码
  8. 使用xlst将xml转换html的示例代码
  9. XML实战秘籍第四卷:选单连动
  10. XML学习(二)详解DOM操作XML文档