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

I'm Ito, an infrastructure engineer.
At our company, we use 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 information on MySQL version upgrades,please 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 being output essentially means the following.
It's output not only when the script is running, but also when you directly enter the password using a command line.
The following is an example of logging in using the mysql command with the -p option and a password as an argument.
You can see that the output is shown 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 only use [-p] and enter the password separately, it won't be displayed.
This is a warning because directly writing the password 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've written other articles about MySQL, so.please check those out as well
7
