Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have multiple [mysqldump] sections in ~/.my.cnf?

After reading the answers on MYSQLDUMP without the password prompt I was wondering :

Is it possible to store multiple credentials, to different db accounts, in one ~/.my.cnf file? If so, what is the syntax?

N.B.: I reckon that could rise security issues but that's strictly for local/dev environment.

like image 638
Édouard Lopez Avatar asked Oct 16 '25 22:10

Édouard Lopez


1 Answers

Asking on IRC #mysql here is what I got:

MrAmmon | not really, no. You can, if you like, have multiple files and reference them, though MrAmmon | example - mysql --defaults-file=~/.my.cnf-bobby

Solution

  1. Create a credentials file for your project ;
  2. Reference it when doing the dump (--defaults-file= must be the first option):
mysqldump --defaults-file="$HOME/.my.project.cnf" -u projectUser --no-create-db --no-create-info projectDb

Others options

There is several argument to control options:

--no-defaults: Don't read default options from any option file.
--defaults-file=#: Only read default options from the given file #.
--defaults-extra-file=#: Read this file after the global files are read.
like image 132
Édouard Lopez Avatar answered Oct 19 '25 11:10

Édouard Lopez