0

I am trying to connect to a remote MySQL Server from a Jenkins job.

I bound the MySQL user credentials into two variables MYSQL_USERNAME and MYSQL_PASSWORD. I need to SSH first, and then connect to MySQL. The shell command I used is:

ssh remote_server mysql --user="$MYSQL_USERNAME" --password="$MYSQL_PASSWORD" -e "SHOW DATABASES;"

(Build Step-> Execute shell)(quotes only for --user, --password and -e)

Summary of Error: Using MySQL credentials on command line is insecure, and I get whole mysql help commands.

Any help is appreciated.

skomisa
  • 16,436
  • 7
  • 61
  • 102
Yashaswini
  • 43
  • 1
  • 5

1 Answers1

0

Double quote the command you're executing remotely, and use single quotes around the parameters

ssh remote_server "mysql --user='$MYSQL_USERNAME' --password='$MYSQL_PASSWORD' -e 'SHOW DATABASES;' 2>/dev/null"

2>/dev/null suppresses the warning, but there are definitely better ways to get around that, like not passing a password on the command line as it suggests.

Adam vonNieda
  • 1,635
  • 2
  • 14
  • 22
  • Thanks for the answer. May I know what is recommended to connect to MySQL database server other than passing password as variable. I have used Credentials binding plugin and added the mysql user credentials on Jenkins global credentials. Using the quotes, worked and thank you.....:) – Yashaswini May 07 '19 at 20:12
  • You're welcome, please mark it as correct if it is. Here's a discussion around the password warning, I'm sure there are plenty of others. https://stackoverflow.com/questions/20751352/suppress-warning-messages-using-mysql-from-within-terminal-but-password-written – Adam vonNieda May 07 '19 at 20:15