加载配置文件顺序:/etc/my.cnf---->/etc/mysql/my.cnf----->/usr/local/mysql/etc/my.cnf---->~/.my.cnf
后面配置文件会覆盖前面配置文件设置的参数
如果/etc/my.cnf配置文件定义了innodb_buffer_pool_size=100M 而/etc/mysql/my.cnf配置文件定义了innodb_buffer_pool_size=200M 则会加载200M的参数
open("/proc/self/status", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fe7602eb000
read(3, "Name:\tmysqld\nState:\tR (running)\n"..., 1024) = 917
read(3, "", 1024) = 0
close(3) = 0
munmap(0x7fe7602eb000, 4096) = 0
futex(0x3b550f1d08, FUTEX_WAKE_PRIVATE, 2147483647) = 0
stat("/etc/my.cnf", {st_mode=S_IFREG|0644, st_size=2479, ...}) = 0
open("/etc/my.cnf", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=2479, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fe7602eb000
read(3, "#my.cnf\n[client]\nport "..., 4096) = 2479
read(3, "", 4096) = 0
close(3) = 0
munmap(0x7fe7602eb000, 4096) = 0
stat("/etc/mysql/my.cnf", 0x7fff3fce89a0) = -1 ENOENT (No such file or directory)
stat("/usr/local/mysql/etc/my.cnf", 0x7fff3fce89a0) = -1 ENOENT (No such file or directory)
stat("/root/.my.cnf", 0x7fff3fce89a0) = -1 ENOENT (No such file or directory)
getrlimit(RLIMIT_NOFILE, {rlim_cur=1024, rlim_max=4*1024}) = 0
setrlimit(RLIMIT_NOFILE, {rlim_cur=65535, rlim_max=65535}) = 0
getrlimit(RLIMIT_NOFILE, {rlim_cur=65535, rlim_max=65535}) = 0
mmap(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fe75ffd0000
最佳启动方式:
[root@vm-test1 data]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf &
[1] 3348
[root@vm-test1 data]#
[root@vm-test1 data]# ps -ef |grep mysql
mysql 3348 3114 4 10:03 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
root 3380 3114 0 10:03 pts/1 00:00:00 grep mysql
[root@vm-test1 data]#
多实例启动方式:
/usr/local/mysql/bin/mysqld_safe --defaults-file=/path/my.cnf & #调用 mysqld
/usr/local/mysql/bin/mysqld --defaults-file=/path/my.cnf & #推荐方式
/usr/local/mysql/bin/mysqld_multi start 3306 #关闭不了数据库,perl 脚本 调用 mysqld_safe和mysqld
几种启动方式关系:
service mysqld start 调用 mysqld_safe 调用 mysqld
Mysqld_multi既可以直接调用mysql_safe 也可以直接调用mysqld
mysqld_safe启动分析
可以读取的配置部分mysqld、server、mysqld_safe
操作系统文件数限制参数配置
Open files 和 max_user_processes参数修改 一个连接占用一个线程
/etc/security/limits.conf
[root@vm-test1 data]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 14708
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 14708
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
[root@vm-test1 data]#
Mysqld_multi 用于管理多实例启动的一个脚本 读取配置文件中的[mysqld_multi],[mysqldN] N需要是一个整数,建议使用端口号表示,这部分的配置在配置文件里面会覆盖[mysqld]部分中的配置 [mysqld_multi] mysqld=/usr/local/mysql/bin/mysqld_safe mysqladmin=/usr/local/mysql/bin/mysqladmin user=root password=xxxxxxxxx log=/data/mysql/mysqld_muti.log #(这里的user、password自己指定,该账号需要有shutdown权限) [mysqld3306] port=3306 datadir=/data/mysql/mysql3306/data socket/tmp/mysql3306.sock server-id=203306 log-bin=/data/mysql/mysql3306/logs/mysql-bin 调用方式 mysqld_multi start|stop|reload|report {port} *mysqld_multi只能识别的配置文件就是在my.cnf,其他配置文件不能识别 环境演示:mysql多实例3306 3307 3308 /etc/my.cnf 使用mysqld_muiti关闭实例BUG修复,不能正常关机 my_print_defaults 参数 发现问题 密码不能识别,密码不能传递 vim /usr/local/mysql/bin/mysqld_multi 在my_print_defaults 后面添加-s参数 可以正常关闭多实例 *Mysql遇到启动错误的第一时间记得看error.log 常见启动错误: 1、权限错误 故障模拟: mysqld_multi stop 3306 chown root:root mysql3306/ -R 开始启动3306实例 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf & 这个时候发现并起不来,直接退出了 使用strace命令进行追踪 strace /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf 2>&1|tee log 再将权限改回来 很简单 就是一个排查的思路 记得使用strace Chown mysql:mysql /data/mysql/mysql3306/ -R 2、参数配置错误导致MySQL起不来 查看error.log都能找到原因 *确保getenforce为disabled状态 perror查看代码错误信息