2

I want to read one of the mysql accounts password from environment variable. Is it possible ? If so how can I do that?

I see there are other ways to do it, but would like to check this option. Also, want to know the pros & cons in doing that way. Since I'm pretty new to Linux environment I'm trying to explore the best possible ways.

Thank you.

5
  • 1
    You can set and read anything pretty much in an env var. Are you wondering if you can auto login to mysql through env vars? Commented Mar 20, 2017 at 23:45
  • @Ilion yes, I want to read it through bash script & connect the instance to update one of the table in mysql DB. Commented Mar 20, 2017 at 23:47
  • 2
    You can use environment variables but I will discourage you from using it. Most system administrators with root privileges are not privileged to see user data and that includes application passwords. These systems administrators can easily navigate the proc filesystem and read your exported environment variables. You're better of putting the password in a hashed file or on filesystems that require authentication such as kerberized nfs. Commented Mar 21, 2017 at 0:18
  • What @alvits says is definitely good thought for a shared hosting environment. If it's hardware you own this is less of a concern. Commented Mar 21, 2017 at 1:50
  • @alvits can you post some sample steps to create a hashed file with password & access it through bash script. Commented Mar 21, 2017 at 16:24

1 Answer 1

1

Environment variables are considered generally secure as someone usually needs access to a user session to retrieve them. Using them also allows you to keep authentication values out of code, which is a plus. On the con side they are temporary and will not survive a server restart unless they are stored within a file which will be parsed on start-up or user session start--depending on your needs.

Bash scripts act just like running commands on the command line, basically, and you do not need to do anything extra special to access environmental variables within them. Just access it like $ENVVAR.

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

Comments

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.