mysql配置文件读取顺序

mysql配置文件读取顺序

命令查看mysqld --help --verbose|grep "my.cnf"

#置文件查找次序:若在多个配置文件中均有设定,则最后找到的最终生效
[root@localhost ~]# mysqld --help --verbose|grep "my.cnf"
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
                      my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default

例如:
使用~/.my.cnf来完成免密登录

[root@localhost ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

#编辑~/.my.cnf,添加一下内容,保存退出
[client]
user=root
password='123456'

[root@localhost ~]# cat ~/.my.cnf
[client]
user=root
password='123456'

#测试
[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>


posted @ 2021-07-25 13:06  EverEternity  阅读(105)  评论(0编辑  收藏  举报