1. 程式人生 > 其它 >mysql配置檔案讀取順序

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>