1.[mysqld_safe]组优先级最高,只要该组能够支持配置的参数与其他任何组中的参数冲突,那么都会以该组为准,如error-log
2.各个组之间的参数,如果某个命令或进程启动后,如mysqld启动命令,有可能加载很多组,如mariadb会加载[mysqld][server][mariadb]等,那么如果这些组之间都定义了相同的参数,比如都定义了error-log,那么以最后一次定义的那个为准,即后面的覆盖前面的。且mysqld服务启动的时候,也可能有多个配置文件,如通过!include引入文件,规范也是一样,如果有2个相同的选项参数被加载,那么后面的覆盖前面的(注意是选项覆盖,不是整个组被覆盖,一个同名的选项组可以出现多次)。
3.各个group都有自己支持的配置参数的定义列表,详细请参加mariadb的官方文档。
地址:https://mariadb.com/kb/en/configuring-mariadb-with-option-files/#client-option-groups
4.其他规则(来自官网):Option File Syntax
The syntax of the MariaDB option files are:
• Lines starting with # are comments.
• Empty lines are ignored.
• Option groups use the syntax [group-name]. See the Option Groups section below for more information on available option groups.
• The same option group can appear multiple times.
• The !include directive can be used to include other option files. See the Including Option Files section below for more information on this syntax.
• The !includedir directive can be used to include all .cnf files (and potentially .ini files) in a given directory. The option files within the directory are read in alphabetical order. See the Including Option File Directories section below for more information on this syntax.
• Dashes (-) and underscores (_) in options are interchangeable.
• Double quotes can be used to quote values
• \n, \r, \t, \b, \s, ", ', and \ are recognized as character escapes for new line, carriage return, tab, backspace, space, double quote, single quote, and backslash respectively.
• Certain option prefixes are supported. See the Option Prefixes section below for information about available option prefixes.
• See the Options section below for information about available options.
Option group 详情参见官网地址:https://mariadb.com/kb/en/configuring-mariadb-with-option-files/#client-option-groups
[root@localhost ~]# mysqld --help -verbose |grep error
200226 10:29:50 [Note] Plugin 'FEEDBACK' is disabled.
200226 10:29:50 [ERROR] mysqld: unknown option '-e'
file (Solves most 'table full' errors)
--console Write error output on screen; don't remove the console
--core-file Write core on errors.
Print all deadlocks to MySQL error log (off by default)
-L, --language=name Client error messages in given language. May be given as
--lc-messages=name Set the language used for the error messages.
Directory where error messages are
error.
--log-slow-query-log-file, --log-error-file, and
--log-error[=name] Log errors to file (instead of stdout). If file name is
--max-connect-errors=#
--max-error-count=# Max number of errors/warnings to store for a statement
max_join_size records return an error
--slave-skip-errors=name
query event returns an error from the provided list
YES = Don't issue an error message (warning only) if a
200226 10:29:50 [ERROR] Aborting
log-error /var/log/mariadb/mariadbmysqld23.log
max-connect-errors 10
max-error-count 64
slave-skip-errors (No default value)
[root@localhost ~]# mysqladmin variables |grep error #可见如果mariadb处于关闭状态,那么该方法获取运行时不可用
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# mysqladmin variables |grep error
| log_error | /var/log/mariadb/mariadbsafee.log |
| max_connect_errors | 10 |
| max_error_count | 64 |
| slave_skip_errors | OFF |
[root@localhost ~]#
[root@localhost ~]# mysqladmin --help --verbose |head -n 20
mysqladmin Ver 9.0 Distrib 5.5.64-MariaDB, for Linux on x86_64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Administration program for the mysqld daemon.
Usage: mysqladmin [OPTIONS] command command....
Default options are read from the following files in the given order:
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf
The following groups are read: mysqladmin client client-server client-mariadb
The following options may be given as the first argument:
--print-defaults Print the program argument list and exit.
--no-defaults Don't read default options from any option file.
The following specify which files/extra groups are read (specified before remaining options):
--defaults-file=# Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.
--defaults-group-suffix=# Additionally read default groups with # appended as a suffix.
-c, --count=# Number of iterations to make. This works with -i
(--sleep) only.
--debug-check Check memory and open file usage at exit.
[root@localhost ~]# mysqld --help --verbose |head -n 20
200226 10:44:01 [Note] Plugin 'FEEDBACK' is disabled.
mysqld Ver 5.5.64-MariaDB for Linux on x86_64 (MariaDB Server)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Starts the MariaDB database server.
Usage: mysqld [OPTIONS]
Default options are read from the following files in the given order:
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf
The following groups are read: mysqld server mysqld-5.5 mariadb mariadb-5.5 client-server
The following options may be given as the first argument:
--print-defaults Print the program argument list and exit.
--no-defaults Don't read default options from any option file.
The following specify which files/extra groups are read (specified before remaining options):
--defaults-file=# Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.
--defaults-group-suffix=# Additionally read default groups with # appended as a suffix.
--allow-suspicious-udfs
Allows use of UDFs consisting of only one symbol xxx()
[ERROR] Aborting的意思是当前配置文件下,如果启动,会导致启动中断从而启动失败。如果配置文件中发现多个错误行,那么一般仅仅报告发现的第一个错误行的内容,因此我们修复了报告错误后,再次执行该命令继续看是否仍报错,即是否有其他错误,如果有继续修复,如果没有则ok啦。检查到错误出现的行内容后,我们可以用grep ‘查询行内容’配置文件地址,利用grep命令具体查询出错内容的行位置。如grep ‘rr=se’ /etc/my.cnf /etc/my.cnf.d/* 这个案例,会从my.cnf以及my.cnf.d目录(默认不递归)下,寻找内容为’rr=se’内容的行位置。注意该命令检测内容不包括[mysqld_safe]的option group组,该组需要单独用mysqld_safe命令独立检测配置,如用mysql_safe –help如果有错,会提示。
[root@localhost ~]# mysqld --help --verbose |head -n 10 #本案例中出现了未识别的参数行,内容为'hi=s'
200226 11:21:16 [Note] Plugin 'FEEDBACK' is disabled.
200226 11:21:16 [ERROR] mysqld: unknown variable 'hi=s'
mysqld Ver 5.5.64-MariaDB for Linux on x86_64 (MariaDB Server)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Starts the MariaDB database server.
Usage: mysqld [OPTIONS]
Default options are read from the following files in the given order:
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf
The following groups are read: mysqld server mysqld-5.5 mariadb mariadb-5.5 client-server
200226 11:21:16 [ERROR] Aborting
[root@localhost ~]# mysqld --help --verbose |head -n 10 #本案例当前系统中没有找到/etc/4my.cnf.d目录。
mysqld: Can't read dir of '/etc/4my.cnf.d' (Errcode: 2)
Fatal error in defaults handling. Program aborted
[root@localhost ~]# mysqld --help --verbose |head -n 10 #本案例/etc/my.cnf中多出了一行内容为’r44’的行
200226 11:13:36 [Note] Plugin 'FEEDBACK' is disabled.
200226 11:13:36 [ERROR] mysqld: unknown option '--r44'
mysqld Ver 5.5.64-MariaDB for Linux on x86_64 (MariaDB Server)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Starts the MariaDB database server.
Usage: mysqld [OPTIONS]
Default options are read from the following files in the given order:
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf
The following groups are read: mysqld server mysqld-5.5 mariadb mariadb-5.5 client-server
200226 11:13:36 [ERROR] Aborting
[root@localhost ~]# mysqld --help --verbose |head -n 10 #正常状态
200226 11:13:55 [Note] Plugin 'FEEDBACK' is disabled.
mysqld Ver 5.5.64-MariaDB for Linux on x86_64 (MariaDB Server)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Starts the MariaDB database server.
Usage: mysqld [OPTIONS]
Default options are read from the following files in the given order:
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf
The following groups are read: mysqld server mysqld-5.5 mariadb mariadb-5.5 client-server
[root@localhost ~]# mysqld_safe –help #本案例多了一行’s1=3’为内容的行。
200226 11:29:28 mysqld_safe unknown option '--s1=3'
Usage: /usr/bin/mysqld_safe [OPTIONS]
--no-defaults Don't read the system defaults file
--core-file-size=LIMIT Limit core files to the specified size
--defaults-file=FILE Use the specified defaults file
--defaults-extra-file=FILE Also use defaults from the specified file
--ledir=DIRECTORY Look for mysqld in the specified directory
--open-files-limit=LIMIT Limit the number of open files
--crash-script=FILE Script to call when mysqld crashes
--timezone=TZ Set the system timezone
--malloc-lib=LIB Preload shared library LIB if available
--mysqld=FILE Use the specified file as mysqld
--mysqld-version=VERSION Use "mysqld-VERSION" as mysqld
--nice=NICE Set the scheduling priority of mysqld
--no-auto-restart Exit after starting mysqld
--nowatch Exit after starting mysqld
--plugin-dir=DIR Plugins are under DIR or DIR/VERSION, if
VERSION is given
--skip-kill-mysqld Don't try to kill stray mysqld processes
--syslog Log messages to syslog with 'logger'
--skip-syslog Log messages to error log (default)
--syslog-tag=TAG Pass -t "mysqld-TAG" to 'logger'
--flush-caches Flush and purge buffers/caches before
starting the server
--numa-interleave Run mysqld with its memory interleaved
on all NUMA nodes
All other options are passed to the mysqld program.
需要注意的是返回的默认加载的参数,一般是直接从默认加载的配置文件中,直接从各个相关option group中读取的,即可能出现重复的配置参数都显示出来(实际程序运行后一般后面的配置如果与前面的配置项相同,以后面的为准),还可能出现一些配置错误的,或mysql无法识别的配置项都会打印出来(这些错误或无法识别可能会导致mysqld等程序启动失败,因此要十分关注,可以用mysqld –help –verbose测试下配置文件是否出错),且即使错误也不会报错,因为该命令仅仅是显示。
Checking Program Options
You can check which options a given program is going to use by using the --print-defaults command-line argument:
Option Description
–print-defaults
Read options from option files, print all option values, and then exit the program.
This command-line argument can be used with most of MariaDB’s command-line tools, not just mysqld. It must be given as the first argument on the command-line. For example:
$ mysqldump --print-defaults
mysqldump would have been started with the following arguments:
--ssl_cert=/etc/my.cnf.d/certificates/client-cert.pem --ssl_key=/etc/my.cnf.d/certificates/client-key.pem --ssl_ca=/etc/my.cnf.d/certificates/ca.pem --ssl-verify-server-cert --max_allowed_packet=1GB
You can also check which options a given program is going to use by using the my_print_defaults utility and providing the names of the option groups that the program reads. For example:
$ my_print_defaults mysqldump client client-server client-mariadb
--ssl_cert=/etc/my.cnf.d/certificates/client-cert.pem
--ssl_key=/etc/my.cnf.d/certificates/client-key.pem
--ssl_ca=/etc/my.cnf.d/certificates/ca.pem
--ssl-verify-server-cert
--max_allowed_packet=1GB
The my_print_defaults utility's --mysqld command-line option provides a shortcut to refer to all of the server option groups:
$ my_print_defaults --mysqld
--log_bin=mariadb-bin
--log_slave_updates=ON
--ssl_cert=/etc/my.cnf.d/certificates/server-cert.pem
--ssl_key=/etc/my.cnf.d/certificates/server-key.pem
--ssl_ca=/etc/my.cnf.d/certificates/ca.pem
[root@localhost ~]# mysqld --print-defaults#看返回值中的hi=s就无法识别,还有一个内容仅仅为ff的行。
mysqld would have been started with the following arguments:
--port=3306 --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --symbolic-links=0 --log-error=/var/log/mariadb/mariadbmysqld.log --hi=s --hii=ssd --ff --log-error=/var/log/mariadb/mariadbserver.log --log-error=/var/log/mariadb/mariadbmysqld23.log