1

I'd rather not execute a query in a shell script with an open text password.

#!/bin/bash
mysql -uuser -hremotehost -pmypassword -e "update my_table set what_time = NOW()";

Is there a way to put mypassword in my local /etc/my.cnf file or something else to keep it out of open text command line?

Assume my remotehost doesn't accept no password for mysql.

0

3 Answers 3

1

As written over at dba it is possible to configure your my.cnf file as the following:

[clienthost1]   # Note: client + host1
user=user
password=mypassword
host=remotehost

and run it as:

mysql --defaults-group-suffix=host1

Kudus to Derek Downey answer at DBA

Sign up to request clarification or add additional context in comments.

1 Comment

Interesting. Is host1 configurable? For example, can I use clientmy_host_name? And then run mysql --defaults-group-suffix=my_host_name?
1

Another option is to use mysql_config_editor and store the data in an encrypted file.

Example:

mysql_config_editor set --user=user --password --host=remotehost
Enter password:

Comments

1

UPDATED ANSWER

Create ~/.my.cnf file and put the following into it:

[foo]
user=user
password=mypassword
host=remotehost

[bar]
user=user2
password=some-other-password
host=127.0.0.1

Then invoke mysql --login-path=foo ... to connect to remotehost or mysql --login-path=bar ... for local host.

1 Comment

does that work with a remote host as well? What if I have a local mysql instance and a remote mysql instance?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.