Ubuntu中MySQL的参数文件my.cnf示例详析
前言
对于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.cnf root@mylnx12:~# locate my.cnf /etc/alternatives/my.cnf /etc/mysql/my.cnf /etc/mysql/my.cnf.fallback /var/lib/dpkg/alternatives/my.cnf root@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
从上面这些信息判断,mysql的参数文件为/etc/mysql/my.cnf, 但是其他几个my.cnf又是什么情况呢?
root@mylnx12:~# ls -lrt /etc/alternatives/my.cnf lrwxrwxrwx 1 root root 20 sep 28 16:28 /etc/alternatives/my.cnf -> /etc/mysql/mysql.cnf
从上面信息可以看出,/etc/alternatives/my.cnf 其实是一个软连接,指向参数文件/etc/mysql/mysql.cnf
root@mylnx12:~# cat /var/lib/dpkg/alternatives/my.cnf auto /etc/mysql/my.cnf /etc/mysql/my.cnf.fallback 100 /etc/mysql/mysql.cnf 200
光从上面这些信息,我们还看不出/var/lib/dpkg/alternatives/my.cnf与其它配置文件my.cnf是什么关系。那么我们先来看看参数文件/etc/mysql/my.cnf,从下面信息,可以看出“/etc/mysql/my.cnf”是全局配置,“~/.my.cnf”隐藏文件是个人用户设置.
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/
但是/etc/mysql/my.cnf参数文件下面没有任何参数设置,只看到下面两行设置,表示导入这两个目录里面的配置文件。
!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 -lrt total 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.cnf root@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.sock nice = 0 [mysqld] # # * basic settings # user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking log_bin = mylnx12_bin server_id = 0 character-set-server=utf8mb4 collation-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 = 16m max_allowed_packet = 100m thread_stack = 192k thread_cache_size = 8 # this replaces the startup script and checks myisam tables if needed # the first time they are touched myisam-recover-options = backup #max_connections = 100 #table_cache = 64 #thread_concurrency = 10 # # * query cache configuration # query_cache_limit = 1m query_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.log expire_logs_days = 10 max_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
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对的支持。
上一篇: 立夏24小时护肤全攻略 清晨给肌肤喂饱水
下一篇: 中医六大神奇点穴急救大法