Mysql-備份免密登入方法
阿新 • • 發佈:2020-08-24
前言:
最近寫資料庫備份指令碼時,將備份使用者和密碼寫到指令碼中執行備份,發現crontab執行備份指令碼時候,mysql報錯提示:Warning: Using a password on the command line interface can be insecure,告知此行為不安全。crontab退出執行指令碼,沒有執行成功。然後就想到做一個備份時候免密登入,不需要使用者和密碼放在指令碼中,即安全又不會報錯的方法。
1:執行mysql_config_editor命令,執行完成後,會在當前使用者目錄生成一個.mylogin.cnf檔案
說明:
--login-path:登入時呼叫的名稱
--user:免密登入的使用者
--host:免密登入的使用者主機
--password:免密登入的使用者密碼
[root@localhost ~]# mysql_config_editor set --login-path=test --user=root --host=localhost --password
2:通過指定生成的.mylogin.cnf檔案直接進入mysql
[root@localhost ~]# mysql --login-path=test Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 20 Server version: 5.6.45 MySQL Community Server (GPL) Copyright (c)2000, 2019, Oracle and/or its affiliates. All rights reserved. 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>