mysql warns about a password on the command line in a script
mysql: [Warning] Using a password on the command line interface can be insecure.Short answer
The warning is correct: a password written after -p can be seen by other users in process listings. Do not hide the message. Remove the password from the command, using a protected option file with a [client] group or a login path made by mysql_config_editor.
Fix it fast
1Find out which cause you have
Find the command in your script that has the password glued to -p or written as --password=value.
grep -n -E -- '-p[^ ]|--password=' backup.sh2Match what you see, then jump to its fix
What does the error look like?
mysql: [Warning] Using a password on the command line interface can be insecure.
Cause 1 of 2
The password is typed into the command
1Check
Any value attached to -p or --password triggers the warning.
ps aux | grep '[m]ysql '2Fix
Store credentials in a login path. The file .mylogin.cnf is kept in your home directory and read by the client programs. Supply the password at the prompt when you run set.
mysql_config_editor set --login-path=backup --host=localhost --user=backup_user --password
mysql --login-path=backup db_name -e "SELECT 1"
mysqldump --login-path=backup db_name > dump.sql3Verify
The command runs with no warning.
mysql_config_editor print --allConfirmed by dev.mysql.com
Cause 2 of 2
A protected option file is a better fit for the script
1Check
Put the password in the [client] group of an option file that only your user can read.
ls -l ~/.my.cnf2Fix
Create the file and limit access to yourself. To use a file with another name, pass --defaults-file=path as the first option on the command line; the manual says it must come before the other options.
cat > ~/.my.cnf <<'CNF'
[client]
user=backup_user
password=your-password-here
CNF
chmod 600 ~/.my.cnf3Verify
The client uses it without any password in the command.
mysql db_name -e 'SELECT 1'Confirmed by dev.mysql.com
How do I stop it coming back?
- Never filter out the warning with 2>/dev/null; it hides real errors too.
- Use a dedicated MySQL account with only the privileges the job needs.
- Keep credential files out of git and out of backups that others can read.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Databases
Installing the Airflow MySQL provider fails on pkg-config or mysqlclient
Building the mysqlclient wheel fails during the install
The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library.
2 causes, each with a fixDatabases
Compiling a C or C++ program that includes mysql.h fails
undefined reference to `mysql_init'
The compiler only finds mysql.h when the MySQL client development files are installed and their folder is on the include path.
3 causes, each with a fixDatabases
An EC2 instance cannot reach its RDS database
Could not open connection to the host, on port <port>: Connect failed
RDS denies all access until a security group allows it.
3 causes, each with a fixDatabases
Locked out of a fresh MariaDB install as root on Mac or Linux
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
A fresh MariaDB root account is not a normal password account.
3 causes, each with a fixDatabases
An Aria table fails with 'Read page with wrong checksum' (error 1030, code 176)
ERROR 1030 (HY000): Got error 176 "Read page with wrong checksum" from storage engine Aria
Code 176 means MariaDB's Aria engine read a data or index page whose checksum does not match, so that table file is damaged.
3 causes, each with a fixDatabases
The client cannot open a TCP connection to MariaDB or MySQL (error 2003)
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (111)
Error 2003 means the client tried a TCP connection to the host and port and nobody answered.
4 causes, each with a fix