通过该段描述,当没有默认的acl时,创建的文件的权限应为mode & ~umask,而一般情况下针对文件来说,系统默认的mode为0666(并不是所有的文件都可以执行),所以实际创建的文件权限应为 0666 & ~umask,当umask为0022时,创建出来的文件的权限应为0644。
[attach]42760[/attach]
2.2 umask对mkdir函数的影响
mkdir函数用的umask的相关形式:
截取相关描述:
[attach]42761[/attach]
在没有默认acl的情况下,创建的目录的权限为 mode & ~umask & 0777,一般情况下,目录的默认的mode为0777,所以实际创建的目录权限应为 0777 & ~umask & 0777,当umask为0022时,创建的目录的权限应为0755。
[attach]42762[/attach]
通过这段源码可以看出,当没有设置UMASK、UMASK_DIR环境变量时,MySQL默认创建文件及目录的权限分别为0660、0700。
4
自定义MySQL相关文件及
目录权限 4.1 初始化过程中文件及目录的权限
4.1.1 方法
MySQL 提供另外一种方法,设置UMASK和UMASK_DIR环境变量,可以影响创建文件和目录的权限:
The default UMASK and UMASK_DIR values are 0660 and 0700, respectively. MySQL assumes that the value forUMASK or UMASK_DIR is in octal if it starts with a zero. For example,setting UMASK=0600 is equivalent toUMASK=384 because 0600 octal is 384 decimal.
The UMASK and UMASK_DIR variables, despite their names, are used as modes, not masks:
If UMASK is set, mysqld uses ($UMASK | 0600) as the mode for file creation, so that newly created files have a mode in the range from 0600 to 0666 (all values octal).
If UMASK_DIR is set, mysqld uses (\$UMASK_DIR | 0700) as the base mode for directory creation, which then is AND-ed with ~(~$UMASK & 0666), so that newly created directories have a mode in the range from 0700 to 0777 (all values octal). The AND operation may remove read and write permissions from the directory mode, but not execute permissions.
简单的把核心内容翻译一下,设置了UMASK及UMASK_DIR之后,生成的文件及目录的权限应分别为:
4.2 启动及MySQL实例运行中创建文件及目录的权限
启动mysql 有两种方式,/etc/init.d/mysql start 或 service mysql start,这两种方式都能够正确的启动MySQL,但实际情况是有差别的,尤其是在设置了上述环境变量的情况下。
查看了service 命令的 manual,描述是这样的:
DESCRIPTION
service runs a System V init script in as predictable environment as possible, removing most environment variables and with current working directory set to /.
通过验证后确实如此,用service 命令启动 会去掉UMASK环境变量:
[attach]42769[/attach]