mysql配置文件

2016/04/04 mysql

#mysql配置文件

在unix系统中,mysql程序,将会按下面的顺序读取配置文件,后面路径的配置,优先级较高

/etc/my.cnf Global options /etc/mysql/my.cnf Global options SYSCONFDIR/my.cnf Global options $MYSQL_HOME/my.cnf Server-specific options defaults-extra-file The file specified with –defaults-extra-file=file_name, if any ~/.my.cnf User-specific options ~/.mylogin.cnf Login path options

~表示系统用户的主目录

SYSCONFDIR是用CMAKE编译时指定的SYSCONFDIR参数,默认是在安装目录下的etc目录下

MYSQL_HOME是一个环境变量,通常是mysql服务指定的my.cnf位置所在的目录,如果MYSQL_HOME没有指定,但是你使用mysqld_safe程序启动mysql,将会尝试设置MYSQL_HOME为以下值

使BASEDIR 和DATADIR值分别为mysql主程序位置,和mysql 数据存储位置(如/usr/local/mysql,/usr/local/mysql/data) 在5.7.8之前,如果my.cnf在DATADIR目录不在BASEDIR目录,mysqld_safe设置MYSQL_HOME为DATADIR目录,否则设置MYSQL_HOME为BASEDIR目录 5.7.8之后,统一设置为BASEDIR

通常DATADIR是在/usr/local/mysql/data,它是在编译时指定的,而不是用mysqld –datadir指定的,这样指定,DATADIR变量是无效的,因为程序在设置–datadir之前就会查找DATADIR

配置格式说明

空行将被忽略 使用;和#进行注释说明,#可以用在语句中间 [group]组配置,其中group是设置针对哪个程序使用配置,如[mysqld],不区分大小写 opt_name,用于在命令行中使用–opt_name opt_name=value 相当于 –opt_name=value在命令行中。 可以使用 “\b”, “\t”, “\n”, “\r”, “\”, and “\s” 代表退格,tab,换行,回车,\,空字符 如果\后面跟的不是上面的内容,则返回原字符内容,如\S,返回S

可以使用引号,如果字符串中包含如#时将会直接显示

如果想指定Windows 下的一个路径,有以下几种方式,windows使用/会用\来处理它

basedir=”C:\Program Files\MySQL\MySQL Server 5.7” basedir=”C:\Program Files\MySQL\MySQL Server 5.7” basedir=”C:/Program Files/MySQL/MySQL Server 5.7” basedir=C:\Program\sFiles\MySQL\MySQL\sServer\s5.7

以下是一个常见的配置 [client]会对所有客户端连接有效

[client] port=3306 socket=/tmp/mysql.sock

[mysqld] port=3306 socket=/tmp/mysql.sock key_buffer_size=16M max_allowed_packet=8M

如果想指定特定版本的mysql使用配置,可以使用 [mysqld-5.7] sql_mode=TRADITIONAL

还可以使用!include包含配置文件 !include /home/mydir/myopt.cnf

!includedir 在指定目录下读取配置文件(以.cnf结尾的文件,windows是.ini),不保证文件读取的顺序 !includedir /home/mydir

只调用属于该程序的组配置

如在my.cnf中包含 !include /home/mydir/myopt.cnf

在/home/mydir/myopt.cnf中包含如下内容 [mysqladmin] force

[mysqld] key_buffer_size=16M

如果my.cnf被mysqld调用,只会使用/home/mydir/myopt.cnf中的[mysqld]组配置 如果my.cnf被mysqladmin调用,只会使用/home/mydir/myopt.cnf中的[mysqladmin]组配置

You can use the escape sequences “\b”, “\t”, “\n”, “\r”, “\”, and “\s” in option values to represent the backspace, tab, newline, carriage return, backslash, and space characters. The escaping rules in option files are:

SYSCONFDIR represents the directory specified with the SYSCONFDIR option to CMake when MySQL was built. By default, this is the etc directory located under the compiled-in installation directory.

MYSQL_HOME is an environment variable containing the path to the directory in which the server-specific my.cnf file resides. If MYSQL_HOME is not set and you start the server using the mysqld_safe program, mysqld_safe attempts to set MYSQL_HOME as follows:

Let BASEDIR and DATADIR represent the path names of the MySQL base directory and data directory, respectively. As of MySQL 5.7.8, if MYSQL_HOME is not set, mysqld_safe sets it to BASEDIR. Prior to MySQL 5.7.8, if there is a my.cnf file in DATADIR but not in BASEDIR, mysqld_safe sets MYSQL_HOME to DATADIR. Otherwise, if there is no my.cnf file in DATADIR, mysqld_safe sets MYSQL_HOME to BASEDIR.

http://dev.mysql.com/doc/refman/5.7/en/option-files.html http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html http://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html http://dev.mysql.com/doc/refman/5.7/en/setting-environment-variables.html


Search

    Table of Contents