HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Are there mysql client environment variables for USER and DB on Linux?

Submitted by: @import:stackexchange-dba··
0
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 ~/mysql_home/db/my.cnf:

[mysql]
user = username
password= ****
host = hostname
database = databasename


Then you can call the client like

MYSQL_HOME=~/mysql_home/db/ mysql


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!

Code Snippets

[mysql]
user = username
password= ****
host = hostname
database = databasename
MYSQL_HOME=~/mysql_home/db/ mysql

Context

StackExchange Database Administrators Q#149817, answer score: 6

Revisions (0)

No revisions yet.