When executing a mysql command in a script, the message "Warning: Using a password on the command line interface can be insecure" appears

My name is Ito and I am an infrastructure engineer.
Our company uses a script to back up our database every night.
The most commonly used version of MySQL is 5.5, but I had an opportunity to use 5.6, and when I installed and ran the script as usual, the following log was displayed
Warning: Using a password on the command line interface can be insecure
*For MySQL version upgrade information, click here.
Even though I was using the same script as before, an unfamiliar warning was being output
It would be fine if it just appeared, but cron sends me an email..
Having your password visible in the command line interface is not secure
The warning message that is output can be simply explained as follows.
In addition to being output by the script, it is also output when you type the password directly into the command.
The following is an example of logging in with the mysql command -p option and adding a password as an argument.
You can see the output on the second line.
# mysql -uroot -ppassword 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 3548981 Server version: 5.6.30-log MySQL Community Server (GPL) Copyright (c) 2000, 2016, 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>
If you use only [-p] and enter a password separately, it will not be output.
This is a warning that writing it directly is not secure!
Write the password to the conf file
The way to avoid this warning is to read from an external file
Create a file to read externally
# vim dbaccess.cnf [client] user = hoge password = hogehoge host = 192.168.1.1 Since this is a file containing the password, limit access rights to the minimum # chmod 400 dbaccess.cnf
All you need to do is read this file in the mysql command or mysqldump command
# mysql --defaults-extra-file=dbaccess.cnf Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 72755232 Server version: 5.6.30-log MySQL Community Server (GPL) Copyright (c) 2000, 2016, 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>
The connection is successful, so just incorporate this into your script
I have written other articles about MySQL, so please take a look at these
7