mysql configuration for specific user

Simmoniz asked:

Is it possible to create different mysql configurations (mysql.cnf files) for specific linux user?

I want to come up with a solution so current user (linux, already authenticated) can have access to mysql by default without having to use -u and -p arguments. Each linux users would already have their mysql user set up with proper permissions on their databases.

Examples of configuration files I would like to set up. By default, the first mysql conf (default.mysql.conf) would be used but if one of the 3 users; root, www-data or bob are logged in, I would like mysql to use the corresponding configuration file. Is it possible to make this work?

default.mysql.conf

...
[client]
# nothing, must authenticate with -u and -p arguments
...

root.mysql.conf

...
[client]
user = mysqlroot
password = AbCdEfG1234pwd
...

www-data.mysql.conf

...
[client]
user = mysqlwwwdata
password = AbCdEfG1234wwwpwd
...

bob.mysql.conf

...
[client]
user = mysqlbob
password = AbCdEfG1234bobpwd
...

My answer:


The file you want to create is $HOME/.my.cnf, in each user’s home directory, from which the MySQL client will read configuration directives for each corresponding user.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.