# mysql password from a file



## balanga (Mar 3, 2017)

Is there any way to logon to mysql by redirecting the password from a file, eg

`mysql -u root <.mysql_secret`


----------



## lostpacket (Mar 3, 2017)

`mysql --user=root --password="$(< ./my_secret)"`
or
`mysql --user=root --password=`cat ./my_secret``


----------



## usdmatt (Mar 3, 2017)

Here's an interesting command to store the password for the current user I found with a few minutes of research. Seems to create a ~/.mylogin.cnf file, after which you can just run `mysql` without any password options specified.

```
mysql_config_editor set --password
```


----------



## SirDice (Mar 3, 2017)

Use ~/.my.cnf:

```
[client]
user=myuser
password=mypassword
```

Or specify one on the command line: `mysql --defaults-extra-file=/some/where/mysql_password` (format of that file is the same as ~/.my.cnf).


----------



## ShelLuser (Mar 3, 2017)

Still... Even though ~/.my.cnf works there's nothing wrong with doing this in a different way (another file which you're using through the cat command or a shell redirect as shown above). As long as you make sure to keep them secured of course.

Here's the thing: ~/.my.cnf would be the first thing an attacker might look for whereas that other weird named file which you're using is likely to be easily overlooked. Of course, one could argue that whenever a 3rd party has access to these files then you'd have much different problems to cope with, but even so...  It is something I always like to keep in mind as well. When it comes to security I often prefer doing things differently, just to avoid the most obvious (theoretical) targets.

Just my 2 cents here of course.


----------

