Warning
Error Code: 57

MySQL Error 57: Insecure CLI Password Use

📦 MySQL
📋

Description

This warning indicates that you are providing your MySQL password directly on the command line interface (CLI) when executing MySQL utilities. While convenient, this method is insecure as it can expose your password to system processes, shell history, and other users on the system.
💬

Error Message

Using a password on the command line interface can be insecure.
🔍

Known Causes

4 known causes
⚠️
Direct Password Argument
Supplying the password as a command-line argument (e.g., `-pMyPassword`) makes it visible in the process list.
⚠️
Shell History Exposure
Passwords entered directly on the command line are often saved in the shell's history file, making them discoverable.
⚠️
Process List Visibility
Other users on the same system can view your password using process monitoring tools like `ps`.
⚠️
Hardcoded in Scripts
Embedding passwords directly within shell scripts or batch files that are executed via the command line.
🛠️

Solutions

3 solutions available

1. Use a MySQL Option File easy

Store credentials in a secure configuration file to avoid command-line exposure.

1
Create a MySQL option file. The default locations are `~/.my.cnf` on Linux/macOS and `%APPDATA%\MySQL\my.cnf` on Windows.
2
Add a `[client]` section to the file and specify your username and password.
[client]
user = your_mysql_user
password = your_mysql_password
3
Set strict file permissions so only you can read the file. On Linux/macOS, use `chmod 600 ~/.my.cnf`.
chmod 600 ~/.my.cnf
4
Now, when you connect using the `mysql` client, it will automatically read the credentials from the option file.
mysql -h your_mysql_host

2. Prompt for Password Interactively easy

Allow the `mysql` client to prompt you for the password, preventing it from being stored or displayed.

1
When connecting via the `mysql` command-line client, omit the `-p` flag or use `-p` without a password immediately following it. The client will then prompt you to enter the password securely.
mysql -h your_mysql_host -u your_mysql_user
2
After entering the command, you will see a prompt like `Enter password:`. Type your password and press Enter. The password will not be displayed on the screen as you type.
Enter password:

3. Use Environment Variables (with caution) medium

Store the password in an environment variable, which is slightly more secure than command-line arguments but still has potential risks.

1
Set the `MYSQL_PWD` environment variable to your MySQL password. This is a less secure method and should be used with caution, especially in shared environments or scripts that might be logged.
export MYSQL_PWD='your_mysql_password'
2
Connect to MySQL using the `mysql` client. It will automatically pick up the password from the `MYSQL_PWD` environment variable.
mysql -h your_mysql_host -u your_mysql_user
3
To remove the environment variable after use, especially in interactive sessions, use `unset MYSQL_PWD`.
unset MYSQL_PWD
🔗

Related Errors

5 related errors