前幾天剛接手一個MySQL數據,操作系統為Ubuntu 16.04.5 LTS, 資料庫版本為5.7.23-0ubuntu0.16.04.1(APT方式安裝的MySQL)。這個操作系統下的MySQL的配置文件my.cnf很多地方都讓人有點不適應(跟之前的MySQL環境有些出入,之前都是維護RHEL、... ...
前幾天剛接手一個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
#