经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库运维 » MySQL » 查看文章
Ubuntu下面MySQL的参数文件my.cnf浅析
来源:cnblogs  作者:潇湘隐者  时间:2018/10/8 9:01:40  对本文有异议

 

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

 

  1. root@mylnx12:~# find / -name "my.cnf"
  1. /etc/alternatives/my.cnf
  1. /etc/mysql/my.cnf
  1. /var/lib/dpkg/alternatives/my.cnf
  1. root@mylnx12:~# locate my.cnf
  1. /etc/alternatives/my.cnf
  1. /etc/mysql/my.cnf
  1. /etc/mysql/my.cnf.fallback
  1. /var/lib/dpkg/alternatives/my.cnf
  1. root@mylnx12:~# mysql --help | grep my.cnf
  1.                       order of preference, my.cnf, $MYSQL_TCP_PORT,
  1. /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
  1. root@mylnx12:~#  mysqld --verbose --help | grep -A 1 'Default options'
  1. Default options are read from the following files in the given order:
  1. /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf

 

从上面这些信息判断,MySQL的参数文件为/etc/mysql/my.cnf, 但是其他几个my.cnf又是什么情况呢?

 

  1. root@mylnx12:~# ls -lrt /etc/alternatives/my.cnf
  1. 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

 

  1. root@mylnx12:~# cat /var/lib/dpkg/alternatives/my.cnf
  1. auto
  1. /etc/mysql/my.cnf
  1.  
  1. /etc/mysql/my.cnf.fallback
  1. 100
  1. /etc/mysql/mysql.cnf
  1. 200

 

光从上面这些信息,我们还看不出/var/lib/dpkg/alternatives/my.cnf与其它配置文件my.cnf是什么关系。那么我们先来看看参数文件/etc/mysql/my.cnf,从下面信息,可以看出/etc/mysql/my.cnf是全局配置,~/.my.cnf隐藏文件是个人用户设置.

 

  1. root@mylnx12:~# cat /etc/mysql/my.cnf
  1. #
  1. # The MySQL database server configuration file.
  1. #
  1. # You can copy this to one of:
  1. # - "/etc/mysql/my.cnf" to set global options,
  1. # - "~/.my.cnf" to set user-specific options.
  1. #
  1. # One can use all long options that the program supports.
  1. # Run program with --help to get a list of available options and with
  1. # --print-defaults to see which it would actually understand and use.
  1. #
  1. # For explanations see
  1. # http://dev.mysql.com/doc/mysql/en/server-system-variables.html
  1.  
  1. #
  1. # * IMPORTANT: Additional settings that can override those from this file!
  1. #   The files must end with '.cnf', otherwise they'll be ignored.
  1. #
  1.  
  1. !includedir /etc/mysql/conf.d/
  1. !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)下面。使用相关参数测试了一下,确实都能生效。这种设置确实有点让刚接触的人有点不适应。暂时先总结到此!

 

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

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号