[Warning] Using a password on the command line interface can be insecure.
阿新 • • 發佈:2021-11-19
解決方法
方法一:修改my.cnf配置檔案
編輯/etc/my.cnf配置檔案
[root@localhost local]# vi /etc/my.cnf
在配置檔案中新增如下內容
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4
host = 主機ip
user = 資料庫使用者名稱
password = '資料庫密碼'
使用命令匯入匯出(指定載入配置檔案)
匯出資料庫
mysqldump --defaults-extra-file=/etc/my.cnf 資料庫名稱 > 資料庫名稱_$(date +%Y%m%d_%H%M%S).sql
匯入資料庫
mysql --defaults-extra-file=/etc/my.cnf 資料庫名稱 < 資料庫名稱_$(date +%Y%m%d_%H%M%S).sql
方法二:直接在linux環境中新增mysql環境
編輯/etc/profile配置檔案
[root@localhost local]# vi /etc/profile
在最後面新增如下內容,儲存並退出
export MYSQL_PWD=資料庫密碼
使配置生效
[root@localhost local]# source /etc/profile
使用mysqldump命令備份資料庫的時候就可以省略-p密碼引數,執行指令碼就不會報錯了
mysqldump -h主機名 -u使用者名稱 資料庫名稱 > /usr/local/dbbackup/資料庫名稱_$(date +%Y%m%d_%H%M%S).sql
是故無冥冥之志者,無昭昭之明;無惛惛之事者,無赫赫之功。
本文來自部落格園,作者:|是吳啊|,轉載請註明原文連結:https://www.cnblogs.com/wuguofeng/p/15577280.html