您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

mysql配置文件生效顺序

bubuko 2022/1/25 19:57:41 mysql 字数 15611 阅读 653 来源 http://www.bubuko.com/infolist-5-1.html

安装完数据库 除了将my.cnf放在/etc/下放在其他地方也是可以的 1 cp /usr/share/mysql/my-default.cnf /etc/my.cnf 今天就看一下这些my.cnf是怎么生效的 看一下生效的my.cnf有哪些 1 2 3 [root@Check2 ~]# mysql ...

安装完数据库 除了将my.cnf放在/etc/下放在其他地方也是可以的

1
cp /usr/share/mysql/my-default .cnf /etc/my .cnf

今天就看一下这些my.cnf是怎么生效的

看一下生效的my.cnf有哪些

1
2
3
[root@Check2 ~] # mysql --help | grep -E ‘*.cnf‘
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my .cnf /etc/mysql/my .cnf /usr/etc/my .cnf ~/.my.cnf

可以看到路径为

1
2
3
4
/etc/my .cnf
/etc/mysql/my .cnf
/usr/etc/my .cnf
~/.my.cnf

在上面路径中都cp一份my.cnf

其中在[mysqld]下添加port不同

1
2
3
4
/etc/my .cnf    #port = 3307
/etc/mysql/my .cnf    #port = 3308
/usr/etc/my .cnf    #port = 3309
~/.my.cnf    #port = 3310

配置好如下:

1
2
3
4
5
6
7
8
[root@Check2 ~] # cat /etc/my.cnf | grep ‘^port‘
port = 3307
[root@Check2 ~] # cat /etc/mysql/my.cnf | grep ‘^port‘
port = 3308
[root@Check2 ~] # cat /usr/etc/my.cnf | grep ‘^port‘
port = 3309
[root@Check2 ~] # cat ~/.my.cnf | grep ‘^port‘
port = 3310

重启数据库看那个my.cnf生效

1
2
3
4
5
[root@Check2 ~] # /etc/init.d/mysql restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@Check2 ~] # netstat -anpt | grep mysqld
tcp        0      0 0.0.0.0:3310                0.0.0.0:*                   LISTEN      2696 /mysqld

可以看到先生效的是~/.my.cnf

将这个文件删除,在看下其他的

1
2
3
4
5
6
7
[root@Check2 ~] # cd ~
[root@Check2 ~] # rm -rf .my.cnf
[root@Check2 ~] # /etc/init.d/mysql restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@Check2 ~] # netstat -anpt | grep mysqld
tcp 0 0 0.0.0.0:3309 0.0.0.0:* LISTEN 2977 /mysqld

继续

1
2
3
4
5
6
[root@Check2 ~] # rm -rf /usr/etc/my.cnf
[root@Check2 ~] # /etc/init.d/mysql restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@Check2 ~] # netstat -anpt | grep mysqld
tcp 0 0 0.0.0.0:3308 0.0.0.0:* LISTEN 3221 /mysqld

现在可以看出生效顺序是反着的

1
2
3
4
1、~/.my.cnf
2、 /usr/etc/my .cnf
3、 /etc/mysql/my .cnf
4、 /etc/my .cnf

mysql配置文件生效顺序

原文:https://www.cnblogs.com/songtianning/p/12700876.html


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶