patternsqlMinor
Are there mysql client environment variables for USER and DB on Linux?
Viewed 0 times
areuserenvironmentclientmysqlforvariableslinuxandthere
Problem
I see that http://dev.mysql.com/doc/refman/5.7/en/environment-variables.html has an option for setting the USER on Windows, but is it possible on Linux? You can do it via the MYSQL_TEST_LOGIN_FILE, but it's a bit convoluted, and requires setting up files with just the right permissions and one for every user you want to have access. Also, is there an environment variable for what database to start using?
Solution
Not that I know of, but you can make a file called my.cnf in a directory that you specify with the MYSQL_HOME environment variable. For example say you have
Then you can call the client like
and it will use those options. Please keep in mind that your password will be readable by whomever can read that file and it isn't encrypted!
~/mysql_home/db/my.cnf:[mysql]
user = username
password= ****
host = hostname
database = databasenameThen you can call the client like
MYSQL_HOME=~/mysql_home/db/ mysqland it will use those options. Please keep in mind that your password will be readable by whomever can read that file and it isn't encrypted!
Code Snippets
[mysql]
user = username
password= ****
host = hostname
database = databasenameMYSQL_HOME=~/mysql_home/db/ mysqlContext
StackExchange Database Administrators Q#149817, answer score: 6
Revisions (0)
No revisions yet.