Ubuntu下面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)。遂研究總結了一下。具體如下所示:
[email protected]:~# find / -name "my.cnf" /etc/alternatives/my.cnf /etc/mysql/my.cnf /var/lib/dpkg/alternatives/my.cnf[email protected]:~# locate my.cnf /etc/alternatives/my.cnf /etc/mysql/my.cnf /etc/mysql/my.cnf.fallback /var/lib/dpkg/alternatives/my.cnf [email protected]:~# mysql --help | grep my.cnf order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf [email protected]:~# 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 又是什麼情況呢?
[email protected]:~# 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
[email protected]:~# 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” 隱藏檔案是個人使用者設定。
[email protected]:~# 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)下面。使用相關引數測試了一下,確實都能生效。這種設定確實有點讓剛接觸的人有點不適應。暫時先總結到此!
[email protected]:~# cd /etc/mysql/mysql.conf.d/ [email protected]:/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 [email protected]:/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